Documentation
¶
Index ¶
- Constants
- func Debug(ctx context.Context, msg string)
- func Debugf(ctx context.Context, format string, vars ...any)
- func Error(ctx context.Context, msg string)
- func Errorf(ctx context.Context, format string, vars ...any)
- func ExtractSpanID(ctx context.Context) (slog.Value, bool)
- func ExtractTraceID(ctx context.Context) (slog.Value, bool)
- func Fatal(msg string)
- func Fatalf(format string, vars ...any)
- func GetLogger(name string) *slog.Logger
- func Info(ctx context.Context, msg string)
- func Infof(ctx context.Context, format string, vars ...any)
- func InitLogger(name string, opts *Options) (err error)
- func Logf(ctx context.Context, level slog.Level, format string, vars ...any)
- func Warn(ctx context.Context, msg string)
- func Warnf(ctx context.Context, format string, vars ...any)
- type Options
Constants ¶
const ( // GinLogLevel gin 日志级别 GinLogLevel = "warn" // GormLogLevel gorm 日志级别 GormLogLevel = "warn" )
Gin, Gorm 默认日志等级为 warn,目的是避免记录过多无关日志 开发者可根据需求自行调整,可选值:debug、info、warn、error
Variables ¶
This section is empty.
Functions ¶
func ExtractSpanID ¶
ExtractSpanID 从 context 中提取 Span ID,若不存在则返回空 ref: https://github.com/samber/slog-gin/blob/4d5fc6c3f623d0fc9b0a7860894c025b1a33fe8c/middleware.go#L289
func ExtractTraceID ¶
ExtractTraceID 从 context 中提取 traceID,若不存在则返回空 ref: https://github.com/samber/slog-gin/blob/4d5fc6c3f623d0fc9b0a7860894c025b1a33fe8c/middleware.go#L289
func Fatalf ¶
Fatalf 打印 fatal 日志到标准输出并退出程序 Q:为什么 Fatalf 是强制使用 stderr 而非 slog.Default() ? A:调用 Fatalf 意味着程序即将退出,此时往标准输出而不是文件打日志是更合理的(避免 Pod 崩溃导致日志无法采集)
func Logf ¶
Logf 打印日志 ref: https://github.com/golang/go/blob/fc9f02c7aec81bcfcc95434d2529e0bb0bc03d66/src/log/slog/example_wrap_test.go#L19 注:该方法只能在 logging 包及其子包(如 logging/slogresty)中使用,不得在业务逻辑中直接使用
Types ¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package slogresty 实现 resty.Logger 接口
|
Package slogresty 实现 resty.Logger 接口 |