logger

package
v0.1.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetDefaultLogger

func SetDefaultLogger(logger Logger)

SetDefaultLogger 设置默认日志器

Types

type Config

type Config struct {
	Level      LogLevel `json:"level" yaml:"level"`
	Format     string   `json:"format" yaml:"format"` // json, text
	Output     string   `json:"output" yaml:"output"` // stdout, stderr, file
	FilePath   string   `json:"file_path" yaml:"file_path"`
	MaxSize    int      `json:"max_size" yaml:"max_size"`       // MB
	MaxBackups int      `json:"max_backups" yaml:"max_backups"` // 保留的备份文件数量
	MaxAge     int      `json:"max_age" yaml:"max_age"`         // 保留天数
	Compress   bool     `json:"compress" yaml:"compress"`       // 是否压缩
}

Config 日志配置

type LogLevel

type LogLevel string

LogLevel 日志级别

const (
	DebugLevel LogLevel = "debug"
	InfoLevel  LogLevel = "info"
	WarnLevel  LogLevel = "warn"
	ErrorLevel LogLevel = "error"
	FatalLevel LogLevel = "fatal"
)

type Logger

type Logger interface {
	Debug(args ...interface{})
	Info(args ...interface{})
	Warn(args ...interface{})
	Error(args ...interface{})
	Fatal(args ...interface{})

	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warnf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})

	WithField(key string, value interface{}) Logger
	WithFields(fields map[string]interface{}) Logger
	WithError(err error) Logger
	WithContext(ctx context.Context) Logger
}

Logger 日志接口

var DefaultLogger Logger

DefaultLogger 默认日志器

func NewLogger

func NewLogger(config *Config) (Logger, error)

NewLogger 创建新的日志器

Jump to

Keyboard shortcuts

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