logx

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Logger is the global logger.

Functions

func ClearGlobalKV

func ClearGlobalKV()

ClearGlobalKV 清空全部全局键值。

func Close

func Close()

Close 刷新并关闭由 New 创建的全部文件 Writer。

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 DeleteGlobalKV

func DeleteGlobalKV(key string)

DeleteGlobalKV 删除指定的全局键值,之后的日志事件不再附带该键。

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 Init

func Init(filename string)

Init 初始化或重新配置全局日志,并同步设置 zerolog 包级日志、slog 默认日志和标准库日志。 日志始终输出到标准输出;filename 非空时同时写入滚动文件。 程序通常先由包初始化建立默认日志,再在读取配置后调用一次 Init。 重新初始化前会关闭此前创建的文件 Writer,程序退出前应调用 Close 完成刷新和关闭。

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 New

func New(filename string) zerolog.Logger

New 创建写入标准输出的 zerolog 日志;filename 非空时同时写入滚动文件。 调试模式下最低级别为 trace,并记录调用位置。 本包按进程维护统一的文件 Writer 生命周期,调用 Init 或 Close 会关闭此前创建的文件 Writer。

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 ...any)

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 ...any)

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 SetGlobalKV

func SetGlobalKV(key string, value any)

SetGlobalKV 设置进程级全局键值,之后所有由本包创建的日志事件都会附带该键值。 重复设置同一个键会覆盖旧值,可并发调用。 全局键值应仅用于 service、version 等进程级标识;与事件字段同名时会产生重复 JSON key, 调用方应保证全局键不与日志字段冲突。请求级的 trace、user 等字段应通过上下文 Logger 传递。

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 ZeroLogger

type ZeroLogger = zerolog.Logger

ZeroLogger 是 zerolog.Logger 的类型别名。

Jump to

Keyboard shortcuts

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