ttlog

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: BSD-2-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger struct {
	// Embedded logger, the functionality of which will be extended.
	*log.Logger
	// contains filtered or unexported fields
}

Logger represents an active logging object. Decorator https://pkg.go.dev/log#Logger . A Logger can be used simultaneously from multiple goroutines; it guaranteesto serialize access to the Writer.

func NewCustomLogger

func NewCustomLogger(writer io.Writer, prefix string, flags int) *Logger

NewCustomLogger creates a new logger object with custom `writer`, `prefix` and `flags`. Rotation does not work in this case. Such logger is widely used in tests.

func NewLogger

func NewLogger(opts *LoggerOpts) *Logger

NewLogger creates a new object of Logger.

func (*Logger) Close

func (logger *Logger) Close() error

Close implements io.Closer, and closes the current logfile.

func (*Logger) GetOpts

func (logger *Logger) GetOpts() *LoggerOpts

GetOpts returns the parameters that were used to create the logger.

func (*Logger) Rotate

func (logger *Logger) Rotate() error

Rotate causes Logger to close the existing log file and immediately create a new one. After rotating, this initiates compression and removal of old log files according to the configuration.

type LoggerOpts

type LoggerOpts struct {
	// Filename is the name of log file.
	Filename string
	// MaxSize is the maximum size in megabytes of the log file
	// before it gets rotated.
	MaxSize int
	// MaxBackups is the maximum number of old log files to retain.
	MaxBackups int
	// MaxAge is the maximum number of days to retain old log files
	// based on the timestamp encoded in their filename.
	MaxAge int
}

LoggerOpts describes the logger options.

Jump to

Keyboard shortcuts

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