logger

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(msg string, args ...any)

Debug ..

func DebugCtx

func DebugCtx(ctx context.Context, msg string, args ...any)

DebugCtx logs at Debug level with trace context.

func Error

func Error(msg string, args ...any)

Error ..

func ErrorCtx

func ErrorCtx(ctx context.Context, msg string, args ...any)

ErrorCtx logs at Error level with trace context.

func GetLevel

func GetLevel() slog.Level

GetLevel returns the current log level.

func Info

func Info(msg string, args ...any)

Info ..

func InfoCtx

func InfoCtx(ctx context.Context, msg string, args ...any)

InfoCtx logs at Info level with trace context.

func LevelHandler

func LevelHandler() http.Handler

LevelHandler returns an http.Handler that exposes dynamic log-level control.

GET  /loglevel  -> {"level":"info"}
PUT  /loglevel  -> body {"level":"debug"}, returns 200 {"level":"debug"} or 400 on error

func NewTraceHandler

func NewTraceHandler(h slog.Handler) slog.Handler

TraceHandler 包装一个 slog.Handler,在每条日志记录上自动追加当前 OpenTelemetry span 的 trace_id / span_id(取自记录的 context)。 仅当 context 中存在有效 span 时才追加,因此需用 *Context 系列方法记录日志:

base := slog.NewJSONHandler(os.Stdout, opts)
slog.SetDefault(slog.New(logger.NewTraceHandler(base)))
slog.InfoContext(ctx, "handled request") // 自动带上 trace_id/span_id

func SetLevel

func SetLevel(level slog.Level)

SetLevel dynamically sets the global log level; takes effect immediately without restart.

func SetLevelByName

func SetLevelByName(name string) error

SetLevelByName sets the log level by name: "debug"/"info"/"warn"/"error" (case-insensitive). Returns an error for unrecognized names without changing the current level.

func Sync

func Sync() error

Sync ..

func Warn

func Warn(msg string, args ...any)

Warn ..

func WarnCtx

func WarnCtx(ctx context.Context, msg string, args ...any)

WarnCtx logs at Warn level with trace context.

Types

This section is empty.

Jump to

Keyboard shortcuts

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