log

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultLoggerName         = "default"
	DefaultOutputLevel        = InfoLevel
	DefaultStackTraceLevel    = NoneLevel
	DefaultOutputPath         = "stdout"
	DefaultErrorOutputPath    = "stderr"
	DefaultRotationMaxAge     = 30
	DefaultRotationMaxSize    = 100 * 1024 * 1024
	DefaultRotationMaxBackups = 1000
)

Variables

This section is empty.

Functions

func Close

func Close() error

Close implements io.Closer.

func Configure

func Configure(opts *Options) error

Configure initializes a functional logging subsystem.

You typically call this once at process startup. Once this call returns, the logging system is ready to accept data.

func Debug

func Debug(field any)

Debug logs to the DEBUG log.

func Debugf

func Debugf(format string, fields ...any)

Debugf logs to the DEBUG log.

func Error

func Error(field any)

Error logs to the ERROR log.

func Errorf

func Errorf(format string, fields ...any)

Errorf logs to the ERROR log.

func Fatal

func Fatal(field any)

Fatal logs to the FATAL log.

func Fatalf

func Fatalf(format string, fields ...any)

Fatalf logs to the FATAL log.

func Info

func Info(field any)

Info logs to the INFO log. Arguments are handled in the manner of fmt.Print; a newline is appended if missing.

func Infof

func Infof(format string, fields ...any)

Infof logs to the INFO log.

func Sync

func Sync() error

Sync flushes any buffered log entries. Processes should normally take care to call Sync before exiting.

func Warn

func Warn(field any)

Warn logs to the WARN log.

func Warnf

func Warnf(format string, fields ...any)

Warnf logs to the WARN log.

Types

type Level

type Level int32

Level is an enumeration of all supported log levels.

const (
	// NoneLevel disables logging
	NoneLevel Level = iota
	// FatalLevel enables fatal level logging
	FatalLevel
	// ErrorLevel enables error level logging
	ErrorLevel
	// WarnLevel enables warn level logging
	WarnLevel
	// InfoLevel enables info level logging
	InfoLevel
	// DebugLevel enables debug level logging
	DebugLevel
)

type Options

type Options struct {
	// OutputPath is a file system path to write the log data to.
	// The special values stdout and stderr can be used to output to the
	// standard I/O streams. This defaults to stdout.
	OutputPath string

	// ErrorOutputPath is a file system path to write logger errors to.
	// The special values stdout and stderr can be used to output to the
	// standard I/O streams. This defaults to stderr.
	ErrorOutputPath string

	// RotateOutputPath is the path to a rotating log file. This file should
	// be automatically rotated over time, based on the rotation parameters such
	// as RotationMaxSize and RotationMaxAge. The default is to not rotate.
	//
	// This path is used as a foundational path. This is where log output is normally
	// saved. When a rotation needs to take place because the file got too big or too
	// old, then the file is renamed by appending a timestamp to the name. Such renamed
	// files are called backups. Once a backup has been created,
	// output resumes to this path.
	RotateOutputPath string

	// RotationMaxSize is the maximum size in megabytes of a log file before it gets
	// rotated. It defaults to 100 megabytes.
	RotationMaxSize int

	// RotationMaxAge is the maximum number of days to retain old log files based on the
	// timestamp encoded in their filename. Note that a day is defined as 24
	// hours and may not exactly correspond to calendar days due to daylight
	// savings, leap seconds, etc. The default is to remove log files
	// older than 30 days.
	RotationMaxAge int

	// RotationMaxBackups is the maximum number of old log files to retain.  The default
	// is to retain at most 1000 logs.
	RotationMaxBackups int

	// JSONEncoding controls whether the log is formatted as JSON.
	JSONEncoding bool

	// OutputLevel controls the log level.
	OutputLevel string

	// StackTraceLevel controls the log level for stack trace.
	StackTraceLevel string

	// LogCaller controls whether to log the caller of a logging function
	LogCaller bool
}

Options defines the set of options supported by component-base logging package.

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions returns a new set of options, initialized to the defaults

func (*Options) AddFlags

func (o *Options) AddFlags(fs *pflag.FlagSet)

AddFlags add logging-format flag.

Jump to

Keyboard shortcuts

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