Documentation
¶
Overview ¶
Package testlog provides control over logging during tests.
Log messages written to a test case's log using t.Logf are only printed if that particular test fails. However, if code under test logs to a log.Logger, slog.Logger, or the defult Loggers via functions in packages log or slog, any test failure in the package will cause all log messages for the package to be printed – even messages from passing tests. This is very confusing.
To avoid that, this package allows test cases to get a Logger or override the standard logger in a way that redirects logging output into the test log. This way, only logs for failing tests appear in test output.
Based on code from here: https://github.com/golang/go/issues/22513
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Override ¶
Override redirects the output of the default loggers to call t.Log. When t and all of its subtests are complete, the original log output is restored.