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.
Index ¶
- 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) SendEverythingToStderr()
- 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 ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
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) 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.