Documentation
¶
Overview ¶
Package logger provides structured logging using slog with request context support.
Index ¶
- Constants
- func ContextWithRequestID(ctx context.Context, requestID string) context.Context
- func ContextWithTraceID(ctx context.Context, traceID string) context.Context
- func ContextWithUserID(ctx context.Context, userID string) context.Context
- func RequestIDFromContext(ctx context.Context) string
- func UserIDFromContext(ctx context.Context) string
- type Logger
Constants ¶
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 ¶
ContextWithRequestID adds a request ID to the context.
func ContextWithTraceID ¶
ContextWithTraceID adds a trace ID to the context.
func ContextWithUserID ¶
ContextWithUserID adds a user ID to the context.
func RequestIDFromContext ¶
RequestIDFromContext extracts the request ID from context.
func UserIDFromContext ¶
UserIDFromContext extracts the user ID from context.
Types ¶
type 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 (*Logger) WithComponent ¶
WithComponent returns a new Logger with the component field.
func (*Logger) WithContext ¶
WithContext returns a new Logger with fields extracted from the context.
func (*Logger) WithRequestID ¶
WithRequestID returns a new Logger with the request ID field.
func (*Logger) WithUserID ¶
WithUserID returns a new Logger with the user ID field.