Documentation ¶
Overview ¶
Package spy provides an implementation of logger that helps test logging.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewLogDummy ¶
NewLogDummy returns dummy logger which discards logged messages on the fly. Useful when logger is required as dependency in unit testing.
Types ¶
type EntryAssertFormatter ¶
type EntryAssertFormatter struct { Underlying logrus.Formatter // contains filtered or unexported fields }
EntryAssertFormatter is a log formatter, which gather all logged entries
func (*EntryAssertFormatter) AllEntriesMatches ¶
func (f *EntryAssertFormatter) AllEntriesMatches(matcher func(entry logrus.Entry) bool) bool
AllEntriesMatches iterates over all stored entries and execute given matcher on it. Return true only if all entries was successful matched
func (*EntryAssertFormatter) AnyMatches ¶
func (f *EntryAssertFormatter) AnyMatches(matcher func(entry logrus.Entry) bool) bool
AnyMatches iterates over all stored entries and execute given matcher on it. Return true if any entries was successful matched
type LogSink ¶
type LogSink struct { RawLogger *logrus.Logger Logger *logrus.Entry // contains filtered or unexported fields }
LogSink is a helper construct for testing logging in unit tests. Beware: all methods are working on copies of of original messages buffer and are safe for multiple uses.
func (*LogSink) AssertErrorLogged ¶
AssertErrorLogged checks whatever a specific string was logged as error.
Compared elements: level, message
Wrapped errors are supported as long as original error message ends up in resulting one.
func (*LogSink) AssertLogged ¶
AssertLogged checks whatever a specific string was logged at a specific level.
Compared elements: level, message
Beware: we are checking for sub-strings and not for the exact match.
func (*LogSink) AssertNotLogged ¶
AssertNotLogged checks whatever a specific string was not logged at a specific level.
Compared elements: level, message
Beware: we are checking for sub-strings and not for the exact match.