log

package
v1.70.3 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2025 License: MIT Imports: 17 Imported by: 87

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_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 added in v1.50.0

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 added in v1.51.0

type Options struct {
	File                 string      `config:"log_file"`        // Log everything to this 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

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

Enabled returns whether this logger is enabled for this level.

func (*OutputHandler) Handle added in v1.70.0

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

Handle outputs a log in the current format

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.

func (*OutputHandler) WithAttrs added in v1.70.0

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 added in v1.70.0

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