Documentation
¶
Index ¶
- func WithAttrs(ctx context.Context, attrs ...slog.Attr) context.Context
- type LogHandler
- func (h *LogHandler) Dump(w io.Writer)
- func (h *LogHandler) DumpString() string
- func (h *LogHandler) Enabled(ctx context.Context, level slog.Level) bool
- func (h *LogHandler) Handle(ctx context.Context, r slog.Record) error
- func (h *LogHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (h *LogHandler) WithGroup(name string) slog.Handler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type LogHandler ¶
type LogHandler struct {
// contains filtered or unexported fields
}
LogHandler is an slog.Handler that forwards records to an inner handler and buffers them so they can be dumped as a table via LogHandler.Dump. All copies produced by slog.Handler.WithAttrs and slog.Handler.WithGroup share the same buffer, so [Dump] can be called on any copy.
func NewLogHandler ¶
func NewLogHandler(inner slog.Handler, level slog.Level) *LogHandler
func (*LogHandler) Dump ¶
func (h *LogHandler) Dump(w io.Writer)
Dump writes the buffered records as a tab-aligned table to w. Columns are LEVEL, MSG, and one column per unique attribute key in order of first appearance.
func (*LogHandler) DumpString ¶
func (h *LogHandler) DumpString() string
DumpString is a convenience wrapper around [Dump] that returns the table as a string.
Click to show internal directories.
Click to hide internal directories.