logger

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package logger provides structured logging using slog with request context support.

Index

Constants

View Source
const (
	// RequestIDKey is the context key for request ID.
	RequestIDKey contextKey = "request_id"
	// UserIDKey is the context key for user ID.
	UserIDKey contextKey = "user_id"
	// TraceIDKey is the context key for trace ID.
	TraceIDKey contextKey = "trace_id"
)

Variables

This section is empty.

Functions

func ContextWithRequestID

func ContextWithRequestID(ctx context.Context, requestID string) context.Context

ContextWithRequestID adds a request ID to the context.

func ContextWithTraceID

func ContextWithTraceID(ctx context.Context, traceID string) context.Context

ContextWithTraceID adds a trace ID to the context.

func ContextWithUserID

func ContextWithUserID(ctx context.Context, userID string) context.Context

ContextWithUserID adds a user ID to the context.

func RequestIDFromContext

func RequestIDFromContext(ctx context.Context) string

RequestIDFromContext extracts the request ID from context.

func UserIDFromContext

func UserIDFromContext(ctx context.Context) string

UserIDFromContext extracts the user ID from context.

Types

type Logger

type Logger struct {
	*slog.Logger
}

Logger wraps slog.Logger with additional context-aware methods.

func Default

func Default() *Logger

Default creates a logger with default settings (INFO level, JSON format).

func New

func New(level slog.Level, json bool) *Logger

New creates a new Logger with the specified level and format.

func (*Logger) WithComponent

func (l *Logger) WithComponent(component string) *Logger

WithComponent returns a new Logger with the component field.

func (*Logger) WithContext

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

WithContext returns a new Logger with fields extracted from the context.

func (*Logger) WithError

func (l *Logger) WithError(err error) *Logger

WithError returns a new Logger with the error field.

func (*Logger) WithRequestID

func (l *Logger) WithRequestID(requestID string) *Logger

WithRequestID returns a new Logger with the request ID field.

func (*Logger) WithUserID

func (l *Logger) WithUserID(userID string) *Logger

WithUserID returns a new Logger with the user ID field.

Jump to

Keyboard shortcuts

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