Documentation
¶
Overview ¶
Package log provides logging for rclone
Index ¶
- Variables
- func InitLogging()
- func Redirected() bool
- func Stack(o any, info string)
- func Trace(o any, format string, a ...any) func(string, ...any)
- type Options
- type OutputHandler
- func (h *OutputHandler) AddOutput(json bool, fn outputFn)
- func (h *OutputHandler) Enabled(_ context.Context, level slog.Level) bool
- func (h *OutputHandler) Handle(ctx context.Context, r slog.Record) (err error)
- func (h *OutputHandler) ResetOutput()
- func (h *OutputHandler) SetLevel(level slog.Level) slog.Level
- func (h *OutputHandler) SetOutput(fn outputFn)
- func (h *OutputHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (h *OutputHandler) WithGroup(name string) slog.Handler
Constants ¶
This section is empty.
Variables ¶
var Handler = defaultHandler()
Handler is the standard handler for the logging.
var OptionsInfo = fs.Options{{ Name: "log_file", Default: "", Help: "Log everything to this file", Groups: "Logging", }, { Name: "log_file_max_size", Default: fs.SizeSuffix(-1), Help: `Maximum size of the log file before it's rotated (eg "10M")`, Groups: "Logging", }, { Name: "log_file_max_backups", Default: 0, Help: "Maximum number of old log files to retain.", Groups: "Logging", }, { Name: "log_file_max_age", Default: fs.Duration(0), Help: `Maximum duration to retain old log files (eg "7d")`, Groups: "Logging", }, { Name: "log_file_compress", Default: false, Help: "If set, compress rotated log files using gzip.", Groups: "Logging", }, { Name: "log_format", Default: logFormatDate | logFormatTime, 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", }, { Name: "windows_event_log_level", Default: fs.LogLevelOff, Help: "Windows Event Log level DEBUG|INFO|NOTICE|ERROR|OFF", Groups: "Logging", Hide: func() fs.OptionVisibility { if runtime.GOOS == "windows" { return 0 } return fs.OptionHideBoth }(), }}
OptionsInfo descripts the Options in use
Functions ¶
func InitLogging ¶
func InitLogging()
InitLogging start the logging as per the command line flags
This is called explicitly from the CLI, the librclone wrapper and the test framework, but not from package init, so that importing rclone as a library has no side effects on the process-wide default slog logger.
func Redirected ¶
func Redirected() bool
Redirected returns true if the log has been redirected from stdout
Types ¶
type Options ¶ added in v1.51.0
type Options struct {
File string `config:"log_file"` // Log everything to this file
MaxSize fs.SizeSuffix `config:"log_file_max_size"` // Max size of log file
MaxBackups int `config:"log_file_max_backups"` // Max backups of log file
MaxAge fs.Duration `config:"log_file_max_age"` // Max age of log file
Compress bool `config:"log_file_compress"` // Set to compress log file
Format logFormat `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
WindowsEventLogLevel fs.LogLevel `config:"windows_event_log_level"`
}
Options contains options for controlling the logging
var Opt Options
Opt is the options for the logger
type OutputHandler ¶ added in v1.70.0
type OutputHandler struct {
// contains filtered or unexported fields
}
OutputHandler is a slog.Handler that writes log records in a format identical to the standard library's `log` package (e.g., "YYYY/MM/DD HH:MM:SS message").
It can also write logs in JSON format identical to logrus.
func NewOutputHandler ¶ added in v1.70.0
func NewOutputHandler(out io.Writer, opts *slog.HandlerOptions, format logFormat) *OutputHandler
NewOutputHandler creates a new OutputHandler with the specified flags.
This is designed to use log/slog but produce output which is backwards compatible with previous rclone versions.
If opts is nil, default options are used, with Level set to slog.LevelInfo.
func (*OutputHandler) AddOutput ¶ added in v1.70.0
func (h *OutputHandler) AddOutput(json bool, fn outputFn)
AddOutput adds an additional logging destination of the type specified.
func (*OutputHandler) Enabled ¶ added in v1.70.0
Enabled returns whether this logger is enabled for this level.
func (*OutputHandler) ResetOutput ¶ added in v1.70.0
func (h *OutputHandler) ResetOutput()
ResetOutput resets the log output to what is was.
func (*OutputHandler) SetLevel ¶ added in v1.70.0
func (h *OutputHandler) SetLevel(level slog.Level) slog.Level
SetLevel sets a new log level, returning the old one.
func (*OutputHandler) SetOutput ¶ added in v1.70.0
func (h *OutputHandler) SetOutput(fn outputFn)
SetOutput sets a new output handler for the log output.
This is for temporarily overriding the output.