logger

package
v1.1.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ctx

func Ctx(ctx context.Context) *zerolog.Logger

Ctx returns the Logger associated with the ctx. If no logger is associated, a disabled logger is returned.

func Debug

func Debug() *zerolog.Event

Debug starts a new message with debug level.

You must call Msg on the returned event in order to send the event.

func Err

func Err(err error) *zerolog.Event

Err starts a new message with error level with err as a field if not nil or with info level if err is nil.

You must call Msg on the returned event in order to send the event.

func Error

func Error() *zerolog.Event

Error starts a new message with error level.

You must call Msg on the returned event in order to send the event.

func Fatal

func Fatal() *zerolog.Event

Fatal starts a new message with fatal level. The os.Exit(1) function is called by the Msg method.

You must call Msg on the returned event in order to send the event.

func Hook

func Hook(h zerolog.Hook) zerolog.Logger

Hook returns a logger with the h Hook.

func Info

func Info() *zerolog.Event

Info starts a new message with info level.

You must call Msg on the returned event in order to send the event.

func Level

func Level(level zerolog.Level) zerolog.Logger

Level creates a child logger with the minimum accepted level set to level.

func Log

func Log() *zerolog.Event

Log starts a new message with no level. Setting zerolog.GlobalLevel to zerolog.Disabled will still disable events produced by this method.

You must call Msg on the returned event in order to send the event.

func NewCustomFileLogger added in v1.0.4

func NewCustomFileLogger(opts ...CustomLoggerOption) (*zerolog.Logger, error)

NewCustomFileLogger 创建自定义文件日志记录器 返回一个 *zerolog.Logger 对象, 系统会自动处理关闭操作 将日志写入指定文件并享受全局的日志切割和格式化配置

func Output

func Output(w io.Writer) zerolog.Logger

Output duplicates the global logger and sets w as its output.

func Panic

func Panic() *zerolog.Event

Panic starts a new message with panic level. The message is also sent to the panic function.

You must call Msg on the returned event in order to send the event.

func Print

func Print(v ...interface{})

Print sends a log event using debug level and no extra field. Arguments are handled in the manner of fmt.Print.

func Printf

func Printf(format string, v ...interface{})

Printf sends a log event using debug level and no extra field. Arguments are handled in the manner of fmt.Printf.

func Sample

func Sample(s zerolog.Sampler) zerolog.Logger

Sample returns a logger with the s sampler.

func Trace

func Trace() *zerolog.Event

Trace starts a new message with trace level.

You must call Msg on the returned event in order to send the event.

func Warn

func Warn() *zerolog.Event

Warn starts a new message with warn level.

You must call Msg on the returned event in order to send the event.

func With

func With() zerolog.Context

With creates a child logger with the field added to its context.

func WithLevel

func WithLevel(level zerolog.Level) *zerolog.Event

WithLevel starts a new message with level.

You must call Msg on the returned event in order to send the event.

Types

type CustomLogger added in v1.0.4

type CustomLogger struct {
	Logger *zerolog.Logger
	// contains filtered or unexported fields
}

CustomLogger 自定义日志记录器(内部使用)

func (*CustomLogger) Close added in v1.0.4

func (cl *CustomLogger) Close() error

Close 关闭日志记录器

type CustomLoggerOption added in v1.0.4

type CustomLoggerOption func(*CustomLoggerOptions)

CustomLoggerOption 自定义日志记录器选项函数类型

func WithLogFile added in v1.0.4

func WithLogFile(logFile string) CustomLoggerOption

WithLogFile 设置日志文件路径

func WithLogLevel added in v1.0.4

func WithLogLevel(level zerolog.Level) CustomLoggerOption

WithLogLevel 设置日志级别

func WithMaxAge added in v1.0.4

func WithMaxAge(maxAge int) CustomLoggerOption

WithMaxAge 设置日志文件最大保留时间 (天)

func WithMaxBackups added in v1.0.4

func WithMaxBackups(maxBackups int) CustomLoggerOption

WithMaxBackups 设置日志文件最大备份数

func WithMaxSize added in v1.0.4

func WithMaxSize(maxSize int64) CustomLoggerOption

WithMaxSize 设置日志文件最大大小 (MB)

type CustomLoggerOptions added in v1.0.4

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

CustomLoggerOptions 自定义日志记录器选项

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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