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 NewJsonHandler ¶
func NewJsonHandler(handlerOptions *slog.HandlerOptions) *Handler
NewJsonHandler returns a handler recording each record as a JSON object in the journal. handlerOptions may be nil.