Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewTestingLogger ¶
NewTestingLogger returns a testing suitable logp.Logger that uses the testing.T as the logger output.
func NewTestingLoggerWithObserver ¶ added in v0.21.6
func NewTestingLoggerWithObserver(t testing.TB, selector string) (*logp.Logger, *observer.ObservedLogs)
NewTestingLoggerWithObserver returns a testing suitable logp.Logger that uses the testing.T as the logger output and an observer.
Types ¶
type Logger ¶ added in v0.25.0
Logger wraps a *logp.Logger and makes it more suitable for tests. Key features:
- All logs are saved on a single temporary log file
- On failures, the log file is kept and its path printed
- Methods to search and wait for log entries are provided, they keep track of the offset, ensuring ordering when when searching for logs
func NewFileLogger ¶ added in v0.25.0
NewFileLogger returns a logger that logs to a file and has methods to search in the logs. If dir is not an empty string, the log file will be generated on this folder. This is useful to make CI collect the logs in case a test fails. If dir is an empty string, the OS temporary folder is used.
The *logp.Logger is embedded into it, so Logger is a drop-in replacement for a *logp.Logger, or the logger can be accessed via [Logger.Logger]
func (*Logger) FindInLogs ¶ added in v0.25.0
FindInLogs searches for str in the log file keeping track of the offset. It returns true if str is found in the logs. If there are any errors, it returns false and the error
func (*Logger) LogContains ¶ added in v0.25.0
LogContains searches for str in the log file keeping track of the offset. If there is any issue reading the log file, then t.Fatalf is called, if str is not present in the logs, t.Errorf is called.
func (*Logger) ResetOffset ¶ added in v0.25.0
func (l *Logger) ResetOffset()
ResetOffset resets the log file offset
func (*Logger) WaitLogsContains ¶ added in v0.25.0
WaitLogsContains waits for the specified string s to be present in the logs within the given timeout duration and fails the test if s is not found. It keeps track of the log file offset, reading only new lines. Each subsequent call to WaitLogsContains will only check logs not yet evaluated. msgAndArgs should be a format string and arguments that will be printed if the logs are not found, providing additional context for debugging.