log

package
v0.0.0-...-916c69f Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debugf

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

func Debugw

func Debugw(msg string, keyvals ...any)

func Errorf

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

func Errorw

func Errorw(err error, msg string, keyvals ...any)

func Fatalf

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

func Fatalw

func Fatalw(msg string, keyvals ...any)

func Infof

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

func Infow

func Infow(msg string, keyvals ...any)

func Init

func Init(opts *Options, options ...Option)

func NewLogger

func NewLogger(opts *Options, options ...Option) *logger

NewLogger 创建一个新的Logger对象.

func Panicf

func Panicf(format string, args ...any)

func Panicw

func Panicw(msg string, keyvals ...any)

func SetLevel

func SetLevel(level string)

func Warnf

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

func Warnw

func Warnw(msg string, keyvals ...any)

Types

type Logger

type Logger interface {
	Debugf(format string, args ...any)
	Debugw(msg string, keyvals ...any)
	Infof(format string, args ...any)
	Infow(msg string, keyvals ...any)
	Warnf(format string, args ...any)
	Warnw(msg string, keyvals ...any)
	Errorf(format string, args ...any)
	Errorw(err error, msg string, keyvals ...any)
	Panicf(format string, args ...any)
	Panicw(msg string, keyvals ...any)
	Fatalf(format string, args ...any)
	Fatalw(msg string, keyvals ...any)
	SetLevel(level string)
	W(ctx context.Context) Logger
	AddCallerSkip(skip int) Logger
	Sync()

	// integrate other loggers
	gormlogger.Interface
}

Logger defines the interface of a logger.

func AddCallerSkip

func AddCallerSkip(skip int) Logger

func Default

func Default() Logger

Default 返回全局 Logger.

func W

func W(ctx context.Context) Logger

W 解析传入的 context,尝试提取关注的键值,并添加到 zap.Logger 结构化日志中.

type Option

type Option func(*logger)

type Options

type Options struct {
	// DisableCaller specifies whether to include caller information in the log.
	DisableCaller bool `json:"disable-caller,omitempty" mapstructure:"disable-caller"`
	// DisableStacktrace specifies whether to record a stack trace for all messages at or above panic level.
	DisableStacktrace bool `json:"disable-stacktrace,omitempty" mapstructure:"disable-stacktrace"`
	// EnableColor specifies whether to output colored logs.
	EnableColor bool `json:"enable-color"       mapstructure:"enable-color"`
	// Level specifies the minimum log level. Valid values are: debug, info, warn, error, dpanic, panic, and fatal.
	Level string `json:"level,omitempty" mapstructure:"level"`
	// Format specifies the log output format. Valid values are: console and json.
	Format string `json:"format,omitempty" mapstructure:"format"`
	// OutputPaths specifies the output paths for the logs.
	OutputPaths []string `json:"output-paths,omitempty" mapstructure:"output-paths"`
	// EnableFile specifies whether to enable file logging.
	EnableFile bool `json:"enable-file,omitempty" mapstructure:"enable-file"`
	// LogDir specifies the directory to store the logs.
	LogDir string `json:"log-dir,omitempty" mapstructure:"log-dir"`
	// MaxSize is the maximum size in megabytes of the log file before it gets rotated.
	MaxSize int `json:"max-size,omitempty" mapstructure:"max-size"`
	// MaxBackups is the maximum number of old log files to retain.
	MaxBackups int `json:"max-backups,omitempty" mapstructure:"max-backups"`
	// MaxAge is the maximum number of days to retain old log files based on the timestamp encoded in their filename.
	MaxAge int `json:"max-age,omitempty" mapstructure:"max-age"`
	// Compress determines if the rotated log files should be compressed using gzip.
	Compress bool `json:"compress,omitempty" mapstructure:"compress"`
}

Options contains configuration options for logging.

func NewOptions

func NewOptions() *Options

NewOptions creates a new Options object with default values.

func (*Options) AddFlags

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

AddFlags adds command line flags for the configuration.

func (*Options) Validate

func (o *Options) Validate() []error

Validate verifies flags passed to LogsOptions.

Jump to

Keyboard shortcuts

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