log: convert options to new style

This commit is contained in:
Nick Craig-Wood 2024-07-04 09:41:32 +01:00
parent eff2497633
commit dce8317042
2 changed files with 37 additions and 18 deletions

View File

@ -14,23 +14,49 @@ import (
"github.com/sirupsen/logrus" "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 // Options contains options for controlling the logging
type Options struct { type Options struct {
File string // Log everything to this file File string `config:"log_file"` // Log everything to this file
Format string // Comma separated list of log format options Format string `config:"log_format"` // Comma separated list of log format options
UseSyslog bool // Use Syslog for logging UseSyslog bool `config:"syslog"` // Use Syslog for logging
SyslogFacility string // Facility for syslog, e.g. KERN,USER,... SyslogFacility string `config:"syslog_facility"` // Facility for syslog, e.g. KERN,USER,...
LogSystemdSupport bool // set if using systemd logging LogSystemdSupport bool `config:"log_systemd"` // set if using systemd logging
} }
// DefaultOpt is the default values used for Opt func init() {
var DefaultOpt = Options{ fs.RegisterGlobalOptions(fs.OptionsInfo{Name: "log", Opt: &Opt, Options: OptionsInfo})
Format: "date,time",
SyslogFacility: "DAEMON",
} }
// Opt is the options for the logger // Opt is the options for the logger
var Opt = DefaultOpt var Opt Options
// fnName returns the name of the calling +2 function // fnName returns the name of the calling +2 function
func fnName() string { func fnName() string {

View File

@ -4,17 +4,10 @@ package logflags
import ( import (
"github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/fs/config/flags"
"github.com/rclone/rclone/fs/log" "github.com/rclone/rclone/fs/log"
"github.com/rclone/rclone/fs/rc"
"github.com/spf13/pflag" "github.com/spf13/pflag"
) )
// AddFlags adds the log flags to the flagSet // AddFlags adds the log flags to the flagSet
func AddFlags(flagSet *pflag.FlagSet) { func AddFlags(flagSet *pflag.FlagSet) {
rc.AddOption("log", &log.Opt) flags.AddFlagsFromOptions(flagSet, "", log.OptionsInfo)
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")
} }