Documentation
¶
Index ¶
- Constants
- func Attrs(ctx context.Context) []slog.Attr
- func Data(ctx context.Context) map[string]any
- func GetLogFilePath(logConfig config.LogConfig) string
- 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 GetLogFilePath ¶
GetLogFilePath returns the resolved log file path. If logConfig.File is empty, it returns the default "activity.log".
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. Always logs to both stdout (text format) and a file (JSON format). The file path defaults to "activity.log" if logConfig.File is empty.
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.