Documentation
¶
Overview ¶
Package mock provides a mock logger implementation for testing slog handlers.
Index ¶
- type Logger
- func (l *Logger) CallStack() core.Stack
- func (l *Logger) Clear()
- func (l *Logger) Debug() slog.Logger
- func (l *Logger) Enabled() bool
- func (l *Logger) Error() slog.Logger
- func (l *Logger) Fatal() slog.Logger
- func (l *Logger) Fields() *internal.FieldsIterator
- func (l *Logger) FieldsCount() int
- func (l *Logger) GetMessages() []Message
- func (l *Logger) Info() slog.Logger
- func (l *Logger) Level() slog.LogLevel
- func (l *Logger) Panic() slog.Logger
- func (l *Logger) Print(args ...any)
- func (l *Logger) Printf(format string, args ...any)
- func (l *Logger) Println(args ...any)
- func (l *Logger) Warn() slog.Logger
- func (l *Logger) WithEnabled() (slog.Logger, bool)
- func (l *Logger) WithField(label string, value any) slog.Logger
- func (l *Logger) WithFields(fields map[string]any) slog.Logger
- func (l *Logger) WithLevel(level slog.LogLevel) slog.Logger
- func (l *Logger) WithStack(skip int) slog.Logger
- type Message
- type Recorder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger implements slog.Logger for testing purposes.
func NewLogger ¶
func NewLogger() *Logger
NewLogger creates a new test logger with a recorder. By default, it logs all levels (no threshold filtering).
func NewLoggerWithThreshold ¶ added in v0.7.8
NewLoggerWithThreshold creates a new test logger with a specific threshold. Only messages at or above the threshold level will be recorded.
func (*Logger) CallStack ¶ added in v0.8.0
CallStack returns the call stack associated with this logger. This method is exposed for testing purposes.
func (*Logger) Clear ¶
func (l *Logger) Clear()
Clear removes all recorded messages from this logger.
func (*Logger) Enabled ¶
Enabled returns whether this logger is enabled and would record at its current level.
func (*Logger) Fields ¶ added in v0.8.0
func (l *Logger) Fields() *internal.FieldsIterator
Fields returns an iterator over all fields in the logger chain. This method is exposed for testing purposes.
func (*Logger) FieldsCount ¶ added in v0.8.0
FieldsCount returns the total number of fields in the logger chain. This method is exposed for testing purposes.
func (*Logger) GetMessages ¶
GetMessages returns all recorded messages from this logger.
func (*Logger) Level ¶ added in v0.8.0
Level returns the current log level. Exposed for testing only.
func (*Logger) WithEnabled ¶
WithEnabled returns the logger and its enabled state.
func (*Logger) WithFields ¶
WithFields implements slog.Logger.
type Message ¶
Message represents a recorded log message for testing.
func (Message) Equal ¶ added in v0.11.0
Equal reports whether two messages carry the same level, text and stack marker, with fields settled key by key through core.AreEqual. Unlike comparing the Message.String rendering, it distinguishes values whose %v text coincides — 1 and "1" — and settles non-comparable values such as slices by content.
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder provides thread-safe recording of log messages for testing.
func NewRecorder ¶
func NewRecorder() *Recorder
NewRecorder creates a new message recorder for testing.
func (*Recorder) GetMessages ¶
GetMessages returns a copy of all recorded messages.