Documentation
¶
Index ¶
- Constants
- func AddCorrelationID(ctx context.Context, correlationID string) context.Context
- func AddRequestID(ctx context.Context, requestID string) context.Context
- func FromContext(ctx context.Context, defaultLogger *slog.Logger) *slog.Logger
- func GetCorrelationID(ctx context.Context) string
- func GetLogger(c *gin.Context) *slog.Logger
- func GetRequestID(ctx context.Context) string
- func New(cfg Config) *slog.Logger
- func NewFromEnv(serviceName string) *slog.Logger
- func Recovery(logger *slog.Logger) gin.HandlerFunc
- func RequestLogger(logger *slog.Logger) gin.HandlerFunc
- func WithContext(ctx context.Context, logger *slog.Logger) *slog.Logger
- type Config
- type ContextKey
Constants ¶
const ( HeaderRequestID = "X-Request-ID" HeaderCorrelationID = "X-Correlation-ID" )
Header names carrying the tracing IDs across services.
Variables ¶
This section is empty.
Functions ¶
func AddCorrelationID ¶
AddCorrelationID adds correlation ID to context
func AddRequestID ¶
AddRequestID adds request ID to context
func FromContext ¶
FromContext retrieves logger from context or returns the default logger
func GetCorrelationID ¶
GetCorrelationID retrieves correlation ID from context
func GetRequestID ¶
GetRequestID retrieves request ID from context
func NewFromEnv ¶
NewFromEnv creates a logger from the standard LOG_LEVEL, LOG_FORMAT, and LOG_SOURCE environment variables. A malformed LOG_SOURCE panics at startup.
func Recovery ¶
func Recovery(logger *slog.Logger) gin.HandlerFunc
Recovery returns a Gin middleware that recovers from panics and logs them
func RequestLogger ¶
func RequestLogger(logger *slog.Logger) gin.HandlerFunc
RequestLogger returns a Gin middleware that logs HTTP requests with structured logging
Types ¶
type Config ¶
type Config struct {
Level string // debug, info, warn, error
Format string // json, text
ServiceName string
AddSource bool // Add source file and line number
}
Config holds logger configuration
type ContextKey ¶
type ContextKey string
ContextKey is the type for context keys
const ( // RequestIDKey is the context key for request ID RequestIDKey ContextKey = "request_id" // CorrelationIDKey is the context key for correlation ID CorrelationIDKey ContextKey = "correlation_id" )