Documentation
¶
Overview ¶
Package journal_handler adapts slog to the systemd journal, recording each record as one journal entry whose priority follows the record's level.
Index ¶
- type Handler
- func (handler *Handler) Enabled(ctx context.Context, level slog.Level) bool
- func (handler *Handler) Handle(ctx context.Context, record slog.Record) error
- func (handler *Handler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (handler *Handler) WithGroup(name string) slog.Handler
- func (handler *Handler) Write(data []byte) (int, error)
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 sits on both sides of an slog handler: it is the slog.Handler a logger writes records to, and the io.Writer the wrapped encoder writes bytes to. The detour exists because a record's level has to become a journal priority, which is known when the record arrives but not when its encoded bytes come back. The level is therefore recorded on the way in and read on the way out, with a lock held across the pair so concurrent records cannot take each other's priority.
func New ¶ added in v1.26.0
New returns a handler recording each slog record as one journal entry, encoded by the handler newEncoder builds. The encoder is built around the returned handler, because the handler is the io.Writer the encoder writes through: that detour is what lets a record's level become the entry's priority.
fields are journal fields added to every entry. SYSLOG_IDENTIFIER is worth setting: without it journald falls back to the process name, which the kernel truncates to 15 characters, so a service with a longer name cannot be selected with "journalctl -t" at all. fields may be nil.