Documentation
¶
Overview ¶
Package logger provides logging implementations for the chroma-go library. This file implements the Logger interface using the standard library's slog package.
Panic Prevention: This implementation follows the codebase panic prevention guidelines: - No use of Must* functions that could panic - All type conversions are safe and explicit - No risky operations like unchecked array access or nil pointer dereferences - Type switches include default cases to handle unexpected types safely
As a library component, this code is designed to never panic in production use.
Index ¶
- type Field
- type Logger
- type NoopLogger
- func (n *NoopLogger) Debug(msg string, fields ...Field)
- func (n *NoopLogger) DebugWithContext(ctx context.Context, msg string, fields ...Field)
- func (n *NoopLogger) Error(msg string, fields ...Field)
- func (n *NoopLogger) ErrorWithContext(ctx context.Context, msg string, fields ...Field)
- func (n *NoopLogger) Info(msg string, fields ...Field)
- func (n *NoopLogger) InfoWithContext(ctx context.Context, msg string, fields ...Field)
- func (n *NoopLogger) IsDebugEnabled() bool
- func (n *NoopLogger) Sync() error
- func (n *NoopLogger) Warn(msg string, fields ...Field)
- func (n *NoopLogger) WarnWithContext(ctx context.Context, msg string, fields ...Field)
- func (n *NoopLogger) With(fields ...Field) Logger
- type SlogLogger
- func (s *SlogLogger) Debug(msg string, fields ...Field)
- func (s *SlogLogger) DebugWithContext(ctx context.Context, msg string, fields ...Field)
- func (s *SlogLogger) Error(msg string, fields ...Field)
- func (s *SlogLogger) ErrorWithContext(ctx context.Context, msg string, fields ...Field)
- func (s *SlogLogger) Info(msg string, fields ...Field)
- func (s *SlogLogger) InfoWithContext(ctx context.Context, msg string, fields ...Field)
- func (s *SlogLogger) IsDebugEnabled() bool
- func (s *SlogLogger) Sync() error
- func (s *SlogLogger) Warn(msg string, fields ...Field)
- func (s *SlogLogger) WarnWithContext(ctx context.Context, msg string, fields ...Field)
- func (s *SlogLogger) With(fields ...Field) Logger
- type ZapLogger
- func (z *ZapLogger) Debug(msg string, fields ...Field)
- func (z *ZapLogger) DebugWithContext(ctx context.Context, msg string, fields ...Field)
- func (z *ZapLogger) Error(msg string, fields ...Field)
- func (z *ZapLogger) ErrorWithContext(ctx context.Context, msg string, fields ...Field)
- func (z *ZapLogger) Info(msg string, fields ...Field)
- func (z *ZapLogger) InfoWithContext(ctx context.Context, msg string, fields ...Field)
- func (z *ZapLogger) IsDebugEnabled() bool
- func (z *ZapLogger) Sync() error
- func (z *ZapLogger) Warn(msg string, fields ...Field)
- func (z *ZapLogger) WarnWithContext(ctx context.Context, msg string, fields ...Field)
- func (z *ZapLogger) With(fields ...Field) Logger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Field ¶
type Field struct {
Key string
Value interface{}
}
Field represents a key-value pair for structured logging
func ErrorField ¶
ErrorField creates an error field. If key is empty, the field will use "_error" as the default key when logged.
type Logger ¶
type Logger interface {
// Standard logging methods
Debug(msg string, fields ...Field)
Info(msg string, fields ...Field)
Warn(msg string, fields ...Field)
Error(msg string, fields ...Field)
// Context-aware logging methods
DebugWithContext(ctx context.Context, msg string, fields ...Field)
InfoWithContext(ctx context.Context, msg string, fields ...Field)
WarnWithContext(ctx context.Context, msg string, fields ...Field)
ErrorWithContext(ctx context.Context, msg string, fields ...Field)
// With returns a new logger with the given fields
With(fields ...Field) Logger
// Enabled returns true if the given level is enabled
IsDebugEnabled() bool
// Sync flushes any buffered log entries. Should be called before program exit.
Sync() error
}
Logger is the interface that wraps basic logging methods. It provides a common interface for different logging implementations.
type NoopLogger ¶
type NoopLogger struct{}
NoopLogger is a logger that doesn't log anything
func (*NoopLogger) Debug ¶
func (n *NoopLogger) Debug(msg string, fields ...Field)
Debug does nothing
func (*NoopLogger) DebugWithContext ¶
func (n *NoopLogger) DebugWithContext(ctx context.Context, msg string, fields ...Field)
DebugWithContext does nothing
func (*NoopLogger) Error ¶
func (n *NoopLogger) Error(msg string, fields ...Field)
Error does nothing
func (*NoopLogger) ErrorWithContext ¶
func (n *NoopLogger) ErrorWithContext(ctx context.Context, msg string, fields ...Field)
ErrorWithContext does nothing
func (*NoopLogger) InfoWithContext ¶
func (n *NoopLogger) InfoWithContext(ctx context.Context, msg string, fields ...Field)
InfoWithContext does nothing
func (*NoopLogger) IsDebugEnabled ¶
func (n *NoopLogger) IsDebugEnabled() bool
IsDebugEnabled always returns false
func (*NoopLogger) WarnWithContext ¶
func (n *NoopLogger) WarnWithContext(ctx context.Context, msg string, fields ...Field)
WarnWithContext does nothing
func (*NoopLogger) With ¶
func (n *NoopLogger) With(fields ...Field) Logger
With returns the same NoopLogger
type SlogLogger ¶
type SlogLogger struct {
// contains filtered or unexported fields
}
SlogLogger is a Logger implementation using the standard library's slog package
func NewDefaultSlogLogger ¶
func NewDefaultSlogLogger() (*SlogLogger, error)
NewDefaultSlogLogger creates a new SlogLogger with JSON handler and production configuration
func NewInfoSlogLogger ¶ added in v0.3.3
func NewInfoSlogLogger() (*SlogLogger, error)
NewInfoSlogLogger creates a new SlogLogger with info level (no debug output)
func NewSlogLogger ¶
func NewSlogLogger(logger *slog.Logger) *SlogLogger
NewSlogLogger creates a new SlogLogger with the provided slog.Logger
func NewSlogLoggerWithHandler ¶
func NewSlogLoggerWithHandler(handler slog.Handler) *SlogLogger
NewSlogLoggerWithHandler creates a new SlogLogger with the provided handler
func NewTextSlogLogger ¶
func NewTextSlogLogger() (*SlogLogger, error)
NewTextSlogLogger creates a new SlogLogger with text handler for human-readable output
func (*SlogLogger) Debug ¶
func (s *SlogLogger) Debug(msg string, fields ...Field)
Debug logs a message at debug level
func (*SlogLogger) DebugWithContext ¶
func (s *SlogLogger) DebugWithContext(ctx context.Context, msg string, fields ...Field)
DebugWithContext logs a message at debug level with context
func (*SlogLogger) Error ¶
func (s *SlogLogger) Error(msg string, fields ...Field)
Error logs a message at error level
func (*SlogLogger) ErrorWithContext ¶
func (s *SlogLogger) ErrorWithContext(ctx context.Context, msg string, fields ...Field)
ErrorWithContext logs a message at error level with context
func (*SlogLogger) Info ¶
func (s *SlogLogger) Info(msg string, fields ...Field)
Info logs a message at info level
func (*SlogLogger) InfoWithContext ¶
func (s *SlogLogger) InfoWithContext(ctx context.Context, msg string, fields ...Field)
InfoWithContext logs a message at info level with context
func (*SlogLogger) IsDebugEnabled ¶
func (s *SlogLogger) IsDebugEnabled() bool
IsDebugEnabled returns true if debug level is enabled
func (*SlogLogger) Sync ¶
func (s *SlogLogger) Sync() error
Sync flushes any buffered log entries slog doesn't require explicit sync, but we implement it for interface compatibility
func (*SlogLogger) Warn ¶
func (s *SlogLogger) Warn(msg string, fields ...Field)
Warn logs a message at warn level
func (*SlogLogger) WarnWithContext ¶
func (s *SlogLogger) WarnWithContext(ctx context.Context, msg string, fields ...Field)
WarnWithContext logs a message at warn level with context
func (*SlogLogger) With ¶
func (s *SlogLogger) With(fields ...Field) Logger
With returns a new logger with the given fields
type ZapLogger ¶
type ZapLogger struct {
// contains filtered or unexported fields
}
ZapLogger is a Logger implementation using uber-go/zap
func NewDefaultZapLogger ¶
NewDefaultZapLogger creates a new ZapLogger with default configuration
func NewDevelopmentZapLogger ¶
NewDevelopmentZapLogger creates a new ZapLogger with development configuration
func NewZapLogger ¶
NewZapLogger creates a new ZapLogger with the provided zap.Logger
func (*ZapLogger) DebugWithContext ¶
DebugWithContext logs a message at debug level with context
func (*ZapLogger) ErrorWithContext ¶
ErrorWithContext logs a message at error level with context
func (*ZapLogger) InfoWithContext ¶
InfoWithContext logs a message at info level with context
func (*ZapLogger) IsDebugEnabled ¶
IsDebugEnabled returns true if debug level is enabled
func (*ZapLogger) WarnWithContext ¶
WarnWithContext logs a message at warn level with context