slog_align – Index | Files

package slog_align

import ""



type AlignedHandler

type AlignedHandler struct {
	// contains filtered or unexported fields

AlignedHandler is a handler for slog that prints values aligned.

func NewAlignedHandler

func NewAlignedHandler(w io.Writer) AlignedHandler

func (AlignedHandler) Enabled

func (h AlignedHandler) Enabled(ctx context.Context, l slog.Level) bool

Enabled reports whether the handler handles records at the given level.

func (AlignedHandler) Handle

func (h AlignedHandler) Handle(ctx context.Context, r slog.Record) error

Handle the Record.

Handle methods that produce output should observe the following rules:

func (*AlignedHandler) SetTimeFormat

func (h *AlignedHandler) SetTimeFormat(fmt string)

SetTimeFormat sets the timestsamp format.

The default is 15:04. Use an empty string to disable outputting a timestamp.

func (AlignedHandler) WithAttrs

func (h AlignedHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs returns a new Handler whose attributes consist of both the receiver's attributes and the arguments.

The Handler owns the slice: it may retain, modify or discard it.

func (AlignedHandler) WithGroup

func (h AlignedHandler) WithGroup(name string) slog.Handler

WithGroup returns a new Handler with the given group appended to the receiver's existing groups.

The keys of all subsequent attributes, whether added by With or in a Record, should be qualified by the sequence of group names.

How this qualification happens is up to the Handler, so long as this Handler's attribute keys differ from those of another Handler with a different sequence of group names.

A Handler should treat WithGroup as starting a Group of Attrs that ends at the end of the log event. That is,

logger.WithGroup("s").LogAttrs(level, msg, slog.Int("a", 1), slog.Int("b", 2))

should behave like

logger.LogAttrs(level, msg, slog.Group("s", slog.Int("a", 1), slog.Int("b", 2)))

Source Files


v0.0.0-20240409133237-ec61269ec200 (latest)
Apr 9, 2024
11 packages
Last checked
3 weeks ago

Tools for package owners.