log

package
v1.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package log provides structured logging with correlation IDs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CorrelationID

func CorrelationID(ctx context.Context) string

CorrelationID extracts the correlation ID from context.

func RequestID

func RequestID(ctx context.Context) string

RequestID extracts the request ID from context.

func SetDefaultLogger

func SetDefaultLogger(l *Logger)

SetDefaultLogger sets the package-level default logger.

func WithCorrelationID

func WithCorrelationID(ctx context.Context, id string) context.Context

WithCorrelationID adds a correlation ID to the context.

func WithRequestID

func WithRequestID(ctx context.Context, id string) context.Context

WithRequestID adds a request 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 Configure

func Configure(cfg config.AppConfig) *Logger

Configure sets up logging based on configuration and sets as default.

func Default

func Default() *Logger

Default returns the default logger.

func NewLogger

func NewLogger(cfg config.AppConfig) *Logger

NewLogger creates a new Logger based on configuration.

func NewLoggerWithWriter

func NewLoggerWithWriter(w io.Writer, format config.LogFormat, level string) *Logger

NewLoggerWithWriter creates a Logger that writes to the specified writer.

func (*Logger) Debug

func (l *Logger) Debug(msg string, args ...any)

Debug logs at debug level.

func (*Logger) DebugContext

func (l *Logger) DebugContext(ctx context.Context, msg string, args ...any)

DebugContext logs at debug level with context.

func (*Logger) Error

func (l *Logger) Error(msg string, args ...any)

Error logs at error level.

func (*Logger) ErrorContext

func (l *Logger) ErrorContext(ctx context.Context, msg string, args ...any)

ErrorContext logs at error level with context.

func (*Logger) Info

func (l *Logger) Info(msg string, args ...any)

Info logs at info level.

func (*Logger) InfoContext

func (l *Logger) InfoContext(ctx context.Context, msg string, args ...any)

InfoContext logs at info level with context.

func (*Logger) SetDefault

func (l *Logger) SetDefault()

SetDefault sets the global default zerolog logger.

func (*Logger) Warn

func (l *Logger) Warn(msg string, args ...any)

Warn logs at warn level.

func (*Logger) WarnContext

func (l *Logger) WarnContext(ctx context.Context, msg string, args ...any)

WarnContext logs at warn level with context.

func (*Logger) With

func (l *Logger) With(args ...any) *Logger

With returns a new Logger with additional attributes.

func (*Logger) WithContext

func (l *Logger) WithContext(ctx context.Context) *Logger

WithContext returns a logger with context values (correlation ID, request ID).

func (*Logger) Zerolog added in v1.1.1

func (l *Logger) Zerolog() zerolog.Logger

Zerolog returns the underlying zerolog.Logger.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL