From dce8317042498aef5f28a59adc069119e45765fb Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 4 Jul 2024 09:41:32 +0100 Subject: [PATCH] log: convert options to new style --- fs/log/log.go | 46 +++++++++++++++++++++++++++++-------- fs/log/logflags/logflags.go | 9 +------- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/fs/log/log.go b/fs/log/log.go index bf2bfd74b..0877f5d72 100644 --- a/fs/log/log.go +++ b/fs/log/log.go @@ -14,23 +14,49 @@ import ( "github.com/sirupsen/logrus" ) +// OptionsInfo descripts the Options in use +var OptionsInfo = fs.Options{{ + Name: "log_file", + Default: "", + Help: "Log everything to this file", + Groups: "Logging", +}, { + Name: "log_format", + Default: "date,time", + Help: "Comma separated list of log format options", + Groups: "Logging", +}, { + Name: "syslog", + Default: false, + Help: "Use Syslog for logging", + Groups: "Logging", +}, { + Name: "syslog_facility", + Default: "DAEMON", + Help: "Facility for syslog, e.g. KERN,USER", + Groups: "Logging", +}, { + Name: "log_systemd", + Default: false, + Help: "Activate systemd integration for the logger", + Groups: "Logging", +}} + // Options contains options for controlling the logging type Options struct { - File string // Log everything to this file - Format string // Comma separated list of log format options - UseSyslog bool // Use Syslog for logging - SyslogFacility string // Facility for syslog, e.g. KERN,USER,... - LogSystemdSupport bool // set if using systemd logging + File string `config:"log_file"` // Log everything to this file + Format string `config:"log_format"` // Comma separated list of log format options + UseSyslog bool `config:"syslog"` // Use Syslog for logging + SyslogFacility string `config:"syslog_facility"` // Facility for syslog, e.g. KERN,USER,... + LogSystemdSupport bool `config:"log_systemd"` // set if using systemd logging } -// DefaultOpt is the default values used for Opt -var DefaultOpt = Options{ - Format: "date,time", - SyslogFacility: "DAEMON", +func init() { + fs.RegisterGlobalOptions(fs.OptionsInfo{Name: "log", Opt: &Opt, Options: OptionsInfo}) } // Opt is the options for the logger -var Opt = DefaultOpt +var Opt Options // fnName returns the name of the calling +2 function func fnName() string { diff --git a/fs/log/logflags/logflags.go b/fs/log/logflags/logflags.go index d1d3c8d89..4c02e7ea5 100644 --- a/fs/log/logflags/logflags.go +++ b/fs/log/logflags/logflags.go @@ -4,17 +4,10 @@ package logflags import ( "github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/fs/log" - "github.com/rclone/rclone/fs/rc" "github.com/spf13/pflag" ) // AddFlags adds the log flags to the flagSet func AddFlags(flagSet *pflag.FlagSet) { - rc.AddOption("log", &log.Opt) - - flags.StringVarP(flagSet, &log.Opt.File, "log-file", "", log.Opt.File, "Log everything to this file", "Logging") - flags.StringVarP(flagSet, &log.Opt.Format, "log-format", "", log.Opt.Format, "Comma separated list of log format options", "Logging") - flags.BoolVarP(flagSet, &log.Opt.UseSyslog, "syslog", "", log.Opt.UseSyslog, "Use Syslog for logging", "Logging") - flags.StringVarP(flagSet, &log.Opt.SyslogFacility, "syslog-facility", "", log.Opt.SyslogFacility, "Facility for syslog, e.g. KERN,USER,...", "Logging") - flags.BoolVarP(flagSet, &log.Opt.LogSystemdSupport, "log-systemd", "", log.Opt.LogSystemdSupport, "Activate systemd integration for the logger", "Logging") + flags.AddFlagsFromOptions(flagSet, "", log.OptionsInfo) }