Documentation
¶
Index ¶
- Constants
- func NewStdLogger(logger *Logger, level Level) *log.Logger
- type EventFn
- type Events
- type Level
- type Logger
- func (log *Logger) BuildInfo(ctx context.Context)
- func (log *Logger) Debug(ctx context.Context, msg string, args ...any)
- func (log *Logger) Debugc(ctx context.Context, caller int, msg string, args ...any)
- func (log *Logger) Error(ctx context.Context, msg string, args ...any)
- func (log *Logger) Errorc(ctx context.Context, caller int, msg string, args ...any)
- func (log *Logger) Info(ctx context.Context, msg string, args ...any)
- func (log *Logger) Infoc(ctx context.Context, caller int, msg string, args ...any)
- func (log *Logger) Warn(ctx context.Context, msg string, args ...any)
- func (log *Logger) Warnc(ctx context.Context, caller int, msg string, args ...any)
- type Record
- type TraceIDFn
Constants ¶
const ( LevelDebug = Level(slog.LevelDebug) LevelInfo = Level(slog.LevelInfo) LevelWarn = Level(slog.LevelWarn) LevelError = Level(slog.LevelError) )
Common log levels wrapped into our custom Level type.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type EventFn ¶
EventFn defines a function type for handling log events. It receives the context and the log record, enabling async or external processing.
type Events ¶
type Events struct {
Debug EventFn // Called for debug-level logs
Info EventFn // Called for info-level logs
Warn EventFn // Called for warning-level logs
Error EventFn // Called for error-level logs
}
Events holds callbacks for different log levels. This allows assigning custom behavior for each log level independently.
type Level ¶
Level is a custom log level type based on slog.Level. It allows extending or customizing logging behavior while staying compatible with slog.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a structured logging wrapper around slog.Handler. It supports trace ID injection, service name tagging, and custom event hooks.
func New ¶
New creates a Logger with the given output, log level, service name, and optional trace ID function.
func NewWithEvents ¶
func NewWithEvents(w io.Writer, minLevel Level, serviceName string, traceIDFn TraceIDFn, events Events) *Logger
NewWithEvents creates a Logger with custom event hooks for different log levels.
func NewWithHandler ¶
NewWithHandler wraps an existing slog.Handler in a Logger.
func (*Logger) BuildInfo ¶
BuildInfo logs the Go build information of the current binary. Useful for debugging and version tracking in production.
type Record ¶
type Record struct {
Time time.Time // Timestamp of the log event
Message string // Main log message
Level Level // Log level
Attributes map[string]any // Additional structured attributes
}
Record represents a structured log entry. Unlike slog.Record, this struct can be easily stored, serialized, or sent over the network.