Documentation
¶
Overview ¶
Package log provides structured logging with correlation IDs.
Index ¶
- func CorrelationID(ctx context.Context) string
- func RequestID(ctx context.Context) string
- func SetDefaultLogger(l *Logger)
- func WithCorrelationID(ctx context.Context, id string) context.Context
- func WithRequestID(ctx context.Context, id string) context.Context
- type ContextKey
- type Logger
- func (l *Logger) Debug(msg string, args ...any)
- func (l *Logger) DebugContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) Error(msg string, args ...any)
- func (l *Logger) ErrorContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) Info(msg string, args ...any)
- func (l *Logger) InfoContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) SetDefault()
- func (l *Logger) Warn(msg string, args ...any)
- func (l *Logger) WarnContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) With(args ...any) *Logger
- func (l *Logger) WithContext(ctx context.Context) *Logger
- func (l *Logger) Zerolog() zerolog.Logger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CorrelationID ¶
CorrelationID extracts the correlation ID from context.
func SetDefaultLogger ¶
func SetDefaultLogger(l *Logger)
SetDefaultLogger sets the package-level default logger.
func WithCorrelationID ¶
WithCorrelationID adds a correlation ID to the context.
Types ¶
type ContextKey ¶
type ContextKey string
ContextKey is a type for context keys to avoid collisions.
const ( CorrelationIDKey ContextKey = "correlation_id" RequestIDKey ContextKey = "request_id" )
Context keys for logging.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger wraps zerolog.Logger with convenience methods.
func NewLoggerWithWriter ¶
NewLoggerWithWriter creates a Logger that writes to the specified writer.
func (*Logger) DebugContext ¶
DebugContext logs at debug level with context.
func (*Logger) ErrorContext ¶
ErrorContext logs at error level with context.
func (*Logger) InfoContext ¶
InfoContext logs at info level with context.
func (*Logger) SetDefault ¶
func (l *Logger) SetDefault()
SetDefault sets the global default zerolog logger.
func (*Logger) WarnContext ¶
WarnContext logs at warn level with context.
func (*Logger) WithContext ¶
WithContext returns a logger with context values (correlation ID, request ID).