Documentation ¶
Index ¶
- func ZapTestLogger(enab zapcore.LevelEnabler) (*ZapLoggerMock, *ObservedLogs)
- type Log
- type LoggedEntry
- type Logger
- type ObservedLogs
- func (o *ObservedLogs) All() []LoggedEntry
- func (o *ObservedLogs) AllUntimed() []LoggedEntry
- func (o *ObservedLogs) Filter(keep func(LoggedEntry) bool) *ObservedLogs
- func (o *ObservedLogs) FilterField(field zapcore.Field) *ObservedLogs
- func (o *ObservedLogs) FilterFieldKey(key string) *ObservedLogs
- func (o *ObservedLogs) FilterLevelExact(level zapcore.Level) *ObservedLogs
- func (o *ObservedLogs) FilterMessage(msg string) *ObservedLogs
- func (o *ObservedLogs) FilterMessageSnippet(snippet string) *ObservedLogs
- func (o *ObservedLogs) Len() int
- func (o *ObservedLogs) TakeAll() []LoggedEntry
- type ZapLoggerMock
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ZapTestLogger ¶
func ZapTestLogger(enab zapcore.LevelEnabler) (*ZapLoggerMock, *ObservedLogs)
Types ¶
type LoggedEntry ¶
An LoggedEntry is an encoding-agnostic representation of a log message. Field availability is context dependant.
func (LoggedEntry) ContextMap ¶
func (e LoggedEntry) ContextMap() map[string]any
ContextMap returns a map for all fields in Context.
type ObservedLogs ¶
type ObservedLogs struct {
// contains filtered or unexported fields
}
ObservedLogs is a concurrency-safe, ordered collection of observed logs.
func New ¶
func New(enab zapcore.LevelEnabler) (zapcore.Core, *ObservedLogs)
New creates a new Core that buffers logs in memory (without any encoding). It's particularly useful in tests.
func (*ObservedLogs) All ¶
func (o *ObservedLogs) All() []LoggedEntry
All returns a copy of all the observed logs.
func (*ObservedLogs) AllUntimed ¶
func (o *ObservedLogs) AllUntimed() []LoggedEntry
AllUntimed returns a copy of all the observed logs, but overwrites the observed timestamps with time.Time's zero value. This is useful when making assertions in tests.
func (*ObservedLogs) Filter ¶
func (o *ObservedLogs) Filter(keep func(LoggedEntry) bool) *ObservedLogs
Filter returns a copy of this ObservedLogs containing only those entries for which the provided function returns true.
func (*ObservedLogs) FilterField ¶
func (o *ObservedLogs) FilterField(field zapcore.Field) *ObservedLogs
FilterField filters entries to those that have the specified field.
func (*ObservedLogs) FilterFieldKey ¶
func (o *ObservedLogs) FilterFieldKey(key string) *ObservedLogs
FilterFieldKey filters entries to those that have the specified key.
func (*ObservedLogs) FilterLevelExact ¶
func (o *ObservedLogs) FilterLevelExact(level zapcore.Level) *ObservedLogs
FilterLevelExact filters entries to those logged at exactly the given level.
func (*ObservedLogs) FilterMessage ¶
func (o *ObservedLogs) FilterMessage(msg string) *ObservedLogs
FilterMessage filters entries to those that have the specified message.
func (*ObservedLogs) FilterMessageSnippet ¶
func (o *ObservedLogs) FilterMessageSnippet(snippet string) *ObservedLogs
FilterMessageSnippet filters entries to those that have a message containing the specified snippet.
func (*ObservedLogs) Len ¶
func (o *ObservedLogs) Len() int
Len returns the number of items in the collection.
func (*ObservedLogs) TakeAll ¶
func (o *ObservedLogs) TakeAll() []LoggedEntry
TakeAll returns a copy of all the observed logs, and truncates the observed slice.
type ZapLoggerMock ¶
type ZapLoggerMock struct {
// contains filtered or unexported fields
}
func (*ZapLoggerMock) Init ¶
func (z *ZapLoggerMock) Init() error
func (*ZapLoggerMock) ProvideLogger ¶
func (z *ZapLoggerMock) ProvideLogger() *Log
func (*ZapLoggerMock) Provides ¶
func (z *ZapLoggerMock) Provides() []*dep.Out
func (*ZapLoggerMock) Serve ¶
func (z *ZapLoggerMock) Serve() chan error
func (*ZapLoggerMock) Stop ¶
func (z *ZapLoggerMock) Stop() error
func (*ZapLoggerMock) Weight ¶
func (z *ZapLoggerMock) Weight() uint