Documentation
¶
Overview ¶
Package logger provides structured logging for the application. It defines LogLevel and LogFormat types, configures the global slog logger, and provides a GORM logger adapter (see gorm.go) that delegates to slog.
Index ¶
- Variables
- func GetSlogLevel(level LogLevel) slog.Level
- func InitDefaultLevel()
- func IsValidLogFormat(format LogFormat) bool
- func IsValidLogLevel(level LogLevel) bool
- func SetGlobalLogger(level LogLevel, format LogFormat, otelEnabled bool)
- type GormLogger
- func (g *GormLogger) Error(ctx context.Context, msg string, args ...any)
- func (g *GormLogger) Info(ctx context.Context, msg string, args ...any)
- func (g *GormLogger) LogMode(level gormlogger.LogLevel) gormlogger.Interface
- func (g *GormLogger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)
- func (g *GormLogger) Warn(ctx context.Context, msg string, args ...any)
- type GormLoggerOption
- type LogFormat
- type LogLevel
Constants ¶
This section is empty.
Variables ¶
var ValidLogFormats = []LogFormat{ LogFormatJSON, LogFormatText, }
ValidLogFormats lists all accepted log format strings.
var ValidLogLevels = []LogLevel{ LogLevelDebug, LogLevelInfo, LogLevelWarn, LogLevelError, }
ValidLogLevels lists all accepted log level strings.
Functions ¶
func GetSlogLevel ¶
GetSlogLevel returns the slog level for the given level string.
func InitDefaultLevel ¶
func InitDefaultLevel()
InitDefaultLevel initializes the default logger with INFO level, JSON format, and OTel disabled. It's safe to call before config is loaded.
func IsValidLogFormat ¶
IsValidLogFormat reports whether the given format string is recognized.
func IsValidLogLevel ¶
IsValidLogLevel reports whether the given level string is recognized.
func SetGlobalLogger ¶
SetGlobalLogger sets the default slog logger. When otelEnabled is true, records are fanned out to stdout (with trace_id/span_id enrichment) and to the OTel log provider via the otelslog bridge.
Types ¶
type GormLogger ¶
type GormLogger struct {
// contains filtered or unexported fields
}
GormLogger adapts slog to gorm's logger.Interface.
func NewGormLogger ¶
func NewGormLogger(opts ...GormLoggerOption) *GormLogger
NewGormLogger creates a GORM logger that delegates to slog.
func (*GormLogger) Error ¶
func (g *GormLogger) Error(ctx context.Context, msg string, args ...any)
Error logs an error-level message.
func (*GormLogger) Info ¶
func (g *GormLogger) Info(ctx context.Context, msg string, args ...any)
Info logs an info-level message.
func (*GormLogger) LogMode ¶
func (g *GormLogger) LogMode(level gormlogger.LogLevel) gormlogger.Interface
LogMode sets the log level for the GORM logger.
type GormLoggerOption ¶
type GormLoggerOption func(*GormLogger)
GormLoggerOption configures a GormLogger.
func WithIgnoreRecordNotFoundError ¶
func WithIgnoreRecordNotFoundError() GormLoggerOption
WithIgnoreRecordNotFoundError suppresses record-not-found log entries.
func WithSlowThreshold ¶
func WithSlowThreshold(d time.Duration) GormLoggerOption
WithSlowThreshold sets the duration above which queries are logged as slow.
type LogLevel ¶
type LogLevel string
LogLevel represents a named logging severity.
const ( // LogLevelDebug is the debug severity level. LogLevelDebug LogLevel = "debug" // LogLevelInfo is the info severity level. LogLevelInfo LogLevel = "info" // LogLevelWarn is the warning severity level. LogLevelWarn LogLevel = "warn" // LogLevelError is the error severity level. LogLevelError LogLevel = "error" )
Directories
¶
| Path | Synopsis |
|---|---|
|
Package slogext provides slog.Handler primitives used internally by the logger package: a trace-context enricher and a fanout multiplexer.
|
Package slogext provides slog.Handler primitives used internally by the logger package: a trace-context enricher and a fanout multiplexer. |