Documentation
¶
Overview ¶
Package testlogger provides a slog handler which can handle t.Parallel() tests while being a global logging handler, redirecting it to the correct underlying logger for each test thread.
This package also muffles certain log messages to reduce noise in the snapshots and to keep the snapshots consistent across runs.
Index ¶
- Constants
- func BeginDirScanMarker()
- func EndDirScanMarker()
- type Handler
- func (tl *Handler) AddInstance(logger cmdlogger.CmdLogger)
- func (tl *Handler) Delete()
- func (tl *Handler) Enabled(ctx context.Context, level slog.Level) bool
- func (tl *Handler) Handle(ctx context.Context, record slog.Record) error
- func (tl *Handler) HasErrored() bool
- func (tl *Handler) HasErroredBecauseInvalidConfig() bool
- func (tl *Handler) SendEverythingToStderr()
- func (tl *Handler) SetHasErrored()
- func (tl *Handler) SetLevel(level slog.Leveler)
- func (tl *Handler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (tl *Handler) WithGroup(g string) slog.Handler
Constants ¶
const BeginDirectoryScan = "---Begin Directory Scan---"
const EndDirectoryScan = "---End Directory Scan---"
Variables ¶
This section is empty.
Functions ¶
func BeginDirScanMarker ¶ added in v2.1.0
func BeginDirScanMarker()
BeginDirScanMarker prints out a directory scanning marker during testing to allow snapshots to sort the scanning order to allow for unsorted file walks.
func EndDirScanMarker ¶ added in v2.1.0
func EndDirScanMarker()
EndDirScanMarker prints out a directory scanning marker during testing to mark the end of directory walks
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler can be set as the global logging handler before the test starts, and individual test cases can add their own instance/implementation of the cmdlogger.CmdLogger interface.
func (*Handler) AddInstance ¶
AddInstance adds a "global" logger to this specific test run.
func (*Handler) Delete ¶
func (tl *Handler) Delete()
Delete removes the logger created by AddInstance() This **must** be called before a test ends, as the same memory address may be reused.
func (*Handler) HasErrored ¶
HasErrored returns true if there have been any calls to Handle with a level of slog.LevelError
func (*Handler) HasErroredBecauseInvalidConfig ¶ added in v2.1.0
HasErroredBecauseInvalidConfig returns true if there have been any calls to Handle with a level of slog.LevelError due to a config file being invalid
func (*Handler) SendEverythingToStderr ¶
func (tl *Handler) SendEverythingToStderr()
SendEverythingToStderr tells the logger to send all logs to stderr regardless of their level.
This is useful if we're expecting to output structured data to stdout such as JSON, which cannot be mixed with other output.
func (*Handler) SetHasErrored ¶ added in v2.3.0
func (tl *Handler) SetHasErrored()