xlog

package
v0.0.0-...-bad164b Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// logFormat
	LOGFORMAT_JSON    = "json"
	LOGFORMAT_CONSOLE = "console"

	// EncoderConfig
	TIME_KEY       = "time"
	LEVLE_KEY      = "level"
	NAME_KEY       = "logger"
	CALLER_KEY     = "caller"
	MESSAGE_KEY    = "msg"
	STACKTRACE_KEY = "stacktrace"

	// 日志归档配置项
	// 每个日志文件保存的最大尺寸 单位:M
	MAX_SIZE = 1
	// 文件最多保存多少天
	MAX_BACKUPS = 5
	// 日志文件最多保存多少个备份
	MAX_AGE = 7
)
View Source
const DefaultLoggerName = "x_logger"
View Source
const ZeroLogEventCallerSkipFrameCount = 2

打印调用函数时,跳过栈帧的数量

Variables

This section is empty.

Functions

func Debug

func Debug() *zerolog.Event

func Error

func Error() *zerolog.Event

func Fatal

func Fatal() *zerolog.Event

func Info

func Info() *zerolog.Event

func Panic

func Panic() *zerolog.Event

func Warn

func Warn() *zerolog.Event

Types

type Logger

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

func NewLogger

func NewLogger(cfg LoggerConfig) *Logger

func (*Logger) ContextLogger

func (l *Logger) ContextLogger(ctx map[string]interface{}) *Logger

可以把 request id ,uin 等放到 context 里面,统一打印

func (*Logger) Debug

func (l *Logger) Debug() *zerolog.Event

func (*Logger) Error

func (l *Logger) Error() *zerolog.Event

func (*Logger) Info

func (l *Logger) Info() *zerolog.Event

func (*Logger) Panic

func (l *Logger) Panic() *zerolog.Event

type LoggerConfig

type LoggerConfig struct {
	Level            string `yaml:"level"` // trace | debug | info | warn | error | fatal | panic
	SaveLoggerAsFile bool   `yaml:"save_logger_as_file"`
	Directory        string `yaml:"directory"` // log file path = Director + ProjectName + LoggerName + .log
	ProjectName      string `yaml:"project_name"`
	LoggerName       string `yaml:"logger_name"`
	MaxSize          int    `yaml:"max_size"`
	MaxBackups       int    `yaml:"max_backups"`
}

Jump to

Keyboard shortcuts

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