mirror of
https://github.com/rclone/rclone.git
synced 2024-11-25 09:41:44 +08:00
log: convert options to new style
This commit is contained in:
parent
eff2497633
commit
dce8317042
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user