Documentation
¶
Overview ¶
Package loggingtest provides logging.Logger implementations for use in tests. New forwards logs to a testing.TB, treating warnings and errors as test failures. NewRecorder captures logs in memory so tests can assert on what was logged without any output.
Index ¶
- type Logger
- func (l *Logger) CancelOnError(ctx context.Context) context.Context
- func (l Logger) Debug(msg string, fs ...zap.Field)
- func (l Logger) Error(msg string, fs ...zap.Field)
- func (l Logger) Fatal(msg string, fs ...zap.Field)
- func (l Logger) Info(msg string, fs ...zap.Field)
- func (l Logger) Trace(msg string, fs ...zap.Field)
- func (l Logger) Warn(msg string, fs ...zap.Field)
- func (l Logger) With(fields ...zap.Field) logging.Logger
- type Record
- type Recorder
- func (l *Recorder) At(lvl logging.Level) []*Record
- func (l *Recorder) AtLeast(lvl logging.Level) []*Record
- func (l Recorder) Debug(msg string, fs ...zap.Field)
- func (l Recorder) Error(msg string, fs ...zap.Field)
- func (l Recorder) Fatal(msg string, fs ...zap.Field)
- func (l *Recorder) Filter(fn func(*Record) bool) []*Record
- func (l Recorder) Info(msg string, fs ...zap.Field)
- func (l Recorder) Trace(msg string, fs ...zap.Field)
- func (l Recorder) Warn(msg string, fs ...zap.Field)
- func (l Recorder) With(fields ...zap.Field) logging.Logger
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 is a logging.Logger that propagates logs to testing.TB.
func New ¶
New constructs a logger that propagates logs to testing.TB. WARNING and ERROR logs are sent to testing.TB.Errorf while FATAL is sent to testing.TB.Fatalf. All other logs are sent to testing.TB.Logf. Although the level can be configured, it is silently capped at logging.Warn.
func (*Logger) CancelOnError ¶
CancelOnError pipes `ctx` to and from context.WithCancel, calling the context.CancelFunc after logs >= logging.Error, and during testing.TB cleanup.
type Recorder ¶
type Recorder struct {
Records []*Record
// contains filtered or unexported fields
}
A Recorder is a logging.Logger that stores all logs as Record entries for inspection.
func NewRecorder ¶
NewRecorder constructs a new Recorder at the specified level.
func (*Recorder) At ¶
At returns all recorded logs at the specified logging.Level.
func (*Recorder) AtLeast ¶
AtLeast returns all recorded logs at or above the specified logging.Level.