log

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

This section is empty.

Types

type Config

type Config struct {
	Base zap.Config

	// MaxSize is the maximum size in megabytes of the log file before it gets
	// rotated. It defaults to 100 megabytes.
	MaxSize int
	// MaxBackups is the maximum number of old log files to retain.  The default
	// is to retain all old log files (though MaxAge may still cause them to get
	// deleted.)
	MaxBackups int
	// LocalTime determines if the time used for formatting the timestamps in
	// backup files is the computer's local time.  The default is to use UTC
	// time.
	LocalTime bool

	// Compress determines if the rotated log files should be compressed
	// using gzip. The default is not to perform compression.
	Compress bool

	// Filename is the file to write logs to.  Backup log files will be retained
	// in the same directory.  It uses <processname>-lumberjack.log in
	// os.TempDir() if empty.
	Filename string

	// MaxAge 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 not to remove old log files
	// based on age.
	MaxAge int

	Interval time.Duration
}

func NewDevelopmentConfig

func NewDevelopmentConfig() Config

func NewProductionConfig

func NewProductionConfig() Config

NewProductionConfig is a reasonable production logging configuration. Logging is enabled at InfoLevel and above.

It uses a JSON encoder, writes to standard error, and enables sampling. Stack traces are automatically included on logs of ErrorLevel and above.

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

func (*Logger) Core

func (log *Logger) Core() zapcore.Core

func (*Logger) GetLogger

func (log *Logger) GetLogger() *Logger

func (*Logger) Sync

func (log *Logger) Sync() error

Sync wrap sync

func (*Logger) WithOptions

func (log *Logger) WithOptions(opts ...zap.Option) *zap.Logger

WithOptions clones the current Logger, applies the supplied Options, and returns the resulting Logger. It's safe to use concurrently.

type LoggerI

type LoggerI interface {
	Sync() error
	Core() zapcore.Core
	WithOptions(opts ...zap.Option) *zap.Logger
	GetLogger() *Logger
}

func NewLogger

func NewLogger(config Config, opts ...Option) LoggerI

type Option

type Option interface {
	// contains filtered or unexported methods
}

An Option configures a Logger.

func WithAlerter

func WithAlerter(alerter diode.AlertFunc) Option

func WithCore

func WithCore(core ...zapcore.Core) Option

func WithLogCompress

func WithLogCompress(compress bool) Option

func WithLogFileName

func WithLogFileName(name string) Option

func WithLogInterval

func WithLogInterval(interval time.Duration) Option

func WithLogLocalTime

func WithLogLocalTime(local bool) Option

func WithLogMaxAge

func WithLogMaxAge(age int) Option

func WithLogMaxBackups

func WithLogMaxBackups(backups int) Option

func WithLogMaxSize

func WithLogMaxSize(size int) Option

func WithZapOptions

func WithZapOptions(opts ...zap.Option) Option

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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