log

package
v1.73.4-bclone Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package log provides logging for rclone

Index

Constants

This section is empty.

Variables

View Source
var Handler = defaultHandler()

Handler is the standard handler for the logging.

View Source
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

func Redirected

func Redirected() bool

Redirected returns true if the log has been redirected from stdout

func Stack

func Stack(o any, info string)

Stack logs a stack trace of callers with the o and info passed in

func Trace

func Trace(o any, format string, a ...any) func(string, ...any)

Trace debugs the entry and exit of the calling function

It is designed to be used in a defer statement, so it returns a function that logs the exit parameters.

Any pointers in the exit function will be dereferenced

Types

type Options

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 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

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

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

func (h *OutputHandler) AddOutput(json bool, fn outputFn)

AddOutput adds an additional logging destination of the type specified.

func (*OutputHandler) Enabled

func (h *OutputHandler) Enabled(_ context.Context, level slog.Level) bool

Enabled returns whether this logger is enabled for this level.

func (*OutputHandler) Handle

func (h *OutputHandler) Handle(ctx context.Context, r slog.Record) (err error)

Handle outputs a log in the current format

func (*OutputHandler) ResetOutput

func (h *OutputHandler) ResetOutput()

ResetOutput resets the log output to what is was.

func (*OutputHandler) SetLevel

func (h *OutputHandler) SetLevel(level slog.Level) slog.Level

SetLevel sets a new log level, returning the old one.

func (*OutputHandler) SetOutput

func (h *OutputHandler) SetOutput(fn outputFn)

SetOutput sets a new output handler for the log output.

This is for temporarily overriding the output.

func (*OutputHandler) WithAttrs

func (h *OutputHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs creates a new handler with the same writer, options, and flags. Attributes are ignored for the output format of this specific handler.

func (*OutputHandler) WithGroup

func (h *OutputHandler) WithGroup(name string) slog.Handler

WithGroup creates a new handler with the same writer, options, and flags. Groups are ignored for the output format of this specific handler.

Directories

Path Synopsis
Package logflags implements command line flags to set up the log
Package logflags implements command line flags to set up the log

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL