Documentation
¶
Index ¶
- Constants
- func Attrs(ctx context.Context) []slog.Attr
- func Data(ctx context.Context) map[string]any
- func IterAttrs(ctx context.Context) func(func(attr slog.Attr) bool)
- func SetupLogRotation(logConfig config.LogConfig) *slog.Logger
- func SetupLogRotationWithFallback(logConfig config.LogConfig, legacyLogLevel string) *slog.Logger
- func With(ctx context.Context, kvargs ...any) context.Context
- func WithAttrs(ctx context.Context, attrs ...slog.Attr) context.Context
- type Config
- type DynamicLeveler
- type Format
- type Handler
- type Hook
- type ReplaceAttrFunc
Constants ¶
const MessageKey = "message"
Variables ¶
This section is empty.
Functions ¶
func IterAttrs ¶
IterAttrs walks through the attributes in the context. The return value is compatible with iter.Seq[slog.Attr] to allow range func.
Example:
for attr := range slogutil.IterAttrs(ctx) {
// DO SOMETHING
}
Feature description: https://tip.golang.org/wiki/RangefuncExperiment
func SetupLogRotation ¶
SetupLogRotation configures slog with log rotation using lumberjack If logConfig.File is empty, it logs to console only If logConfig.File is configured, it logs to both console and file Returns the configured logger
func SetupLogRotationWithFallback ¶
SetupLogRotationWithFallback sets up log rotation with backward compatibility It checks both new log config and legacy log_level setting
Types ¶
type DynamicLeveler ¶
type DynamicLeveler struct {
// contains filtered or unexported fields
}
func (*DynamicLeveler) Level ¶
func (dl *DynamicLeveler) Level() slog.Level
Level returns the current logging level.
func (*DynamicLeveler) SetLevel ¶
func (dl *DynamicLeveler) SetLevel(level slog.Level)
SetLevel updates the logging level.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is a slog.Handler with hooks support.
func NewHandler ¶
NewHandler creates a new Handler with the given configuration.
func WrapHandler ¶
WrapHandler creates a new Handler with the given slog.Handler. If the provided handler is nil, a default JSON handler is used.