Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultContextMappings = []ContextKeyMapping{ {CtxKey: public.TraceIDKey, LogKey: "trace_id"}, {CtxKey: public.SpanIDKey, LogKey: "span_id"}, {CtxKey: public.ParentSpanIDKey, LogKey: "parent_span_id"}, }
DefaultContextMappings are the keys extracted from the context by default. It includes common tracing keys used across the project.
var ErrNotContextLogger = errors.New("provided logger does not implement ContextLogger interface")
var ErrNotSLogger = errors.New("provided logger does not implement SLogger interface")
Functions ¶
func GlobalSlog ¶
GlobalSlog returns a *slog.Logger that wraps the current logger, if available. If the logger is nil, it returns slog.Default().
Types ¶
type ContextKeyMapping ¶
type ContextLogger ¶
type ContextLogger interface {
Logger
ContextDebug(ctx context.Context, msg string, keysAndValues ...interface{})
ContextInfo(ctx context.Context, msg string, keysAndValues ...interface{})
ContextWarn(ctx context.Context, msg string, keysAndValues ...interface{})
ContextError(ctx context.Context, msg string, keysAndValues ...interface{})
ContextDebugf(ctx context.Context, msg string, keysAndValues ...interface{})
ContextInfof(ctx context.Context, msg string, keysAndValues ...interface{})
ContextWarnf(ctx context.Context, msg string, keysAndValues ...interface{})
ContextErrorf(ctx context.Context, msg string, keysAndValues ...interface{})
WithContextKeys(keys ...ContextKeyMapping) ContextLogger
}
func MustWrapContextLogger ¶
func MustWrapContextLogger(lg Logger) ContextLogger
func NewZapContextLogger ¶
func NewZapContextLogger(opts ...Option) (ContextLogger, error)
func WrapContextLogger ¶
func WrapContextLogger(lg Logger) (ContextLogger, error)
type FullLogger ¶
type FullLogger interface {
Logger
ContextLogger
SLogger
}
type Logger ¶
type Logger interface {
Debug(msg string, keysAndValues ...interface{})
Info(msg string, keysAndValues ...interface{})
Warn(msg string, keysAndValues ...interface{})
Error(msg string, keysAndValues ...interface{})
Fatal(msg string, keysAndValues ...interface{})
Debugf(msg string, keysAndValues ...interface{})
Infof(msg string, keysAndValues ...interface{})
Warnf(msg string, keysAndValues ...interface{})
Errorf(msg string, keysAndValues ...interface{})
Fatalf(msg string, keysAndValues ...interface{})
With(keysAndValues ...interface{}) Logger
Sync() error
}
Logger defines the abstract logging interface for the application. It supports structured logging via key-value pairs and allows context accumulation.
func NewZapLogger ¶
NewZapLogger creates a new Logger using zap with the provided options.
type Option ¶
type Option func(*options)
Option is a function that configures the zap logger.
func WithFileRotator ¶
WithFileRotator configures the log file rotation settings. filename: path to the log file. maxSize: max size in megabytes before rotation. maxBackups: max number of old log files to keep. maxAge: max number of days to retain old log files. compress: whether to compress old log files (gzip).
func WithFormat ¶
WithFormat sets the encoding format ("json" or "console").
func WithStdout ¶
WithStdout determines if logs should also be written to standard output. This is useful when writing to a file but also wanting to see logs in the console.
type SLogger ¶
type SLogger interface {
Logger
// Slog returns a *slog.Logger representation of the logger.
Slog() *slog.Logger
// WithSlogContextKeys returns a new logger that extracts the provided keys from context in Slog.
WithSlogContextKeys(keys ...ContextKeyMapping) SLogger
}
SLogger defines the abstract context logging interface which use slog to handle context