Documentation
¶
Overview ¶
Package slogjournal provides a handler for the systemd journal. The journal only accepts keys of the form ^[A-Z_][A-Z0-9_]*$.
Index ¶
Constants ¶
const ( LevelNotice slog.Level = slog.LevelInfo + 1 LevelCritical slog.Level = slog.LevelError + 1 LevelAlert slog.Level = slog.LevelError + 2 LevelEmergency slog.Level = slog.LevelError + 3 )
Names of levels corresponding to syslog.Priority values.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler sends logs to the systemd journal. The journal only accepts keys of the form ^[A-Z_][A-Z0-9_]*$.
func NewHandler ¶
NewHandler returns a new Handler that writes to the systemd journal. The journal only accepts keys of the form ^[A-Z_][A-Z0-9_]*$. If opts is nil, the default options are used. If opts.Level is nil, the default level is a LevelVar which is equivalent to slog.LevelInfo unless the environment variable DEBUG_INVOCATION is set, in which case it is slog.LevelDebug.
func (*Handler) Enabled ¶
Enabled reports whether the handler handles records at the given level. The handler ignores records whose level is lower. It is called early, before any arguments are processed, to save effort if the log event should be discarded.
func (*Handler) Handle ¶
Handle handles the Record and formats it as a journal message. The Message field maps to the MESSAGE field in the journal. The Level field maps to the PRIORITY field in the journal. The PC field maps to the CODE_FILE, CODE_FUNC and CODE_LINE fields in the journal. The Time field maps to the SYSLOG_TIMESTAMP field in the journal. The Attrs field maps to the [KEY=VALUE] fields in the journal. The SYSLOG_IDENTIFIER field is set to the base name of the program. Journal only supports keys of the form ^[A-Z_][A-Z0-9_]*$. Keys starting with an underscore are reserved for internal use and will be dropped. Any other keys will be silently dropped.
Message keys may appear multiple times. Message values may contain arbitrary binary data. If the message does not fit in a single datagram, the message is sent as a file descriptor pointing to a tempfd. If the tempfd feature is not available, the message is sent as a file descriptor pointing to a temporary file in /dev/shm.
type LevelVar ¶
LevelVar is similar to slog.LevelVar but also implements the service side of RestartMode=debug. It looks if the environment variable DEBUG_INVOCATION is set and if so, sets the level to slog.LevelDebug. The zero value of LevelVar is equivalent to slog.LevelInfo. In the future, we might extend the behaviour of LevelVar to implement org.freedesktop.LogControl1.
type Options ¶
type Options struct {
Level slog.Leveler
// ReplaceAttr is called on all non-builtin Attrs before they are written.
// This can be useful for processing attributes to be in the correct format
// for log statements outside of your own code as the journal only accepts
// keys of the form ^[A-Z_][A-Z0-9_]*$.
ReplaceAttr func(groups []string, a slog.Attr) slog.Attr
// ReplaceGroup is called on all group names before they are written. This
// can be useful for processing group names to be in the correct format for
// log statements outside of your own code as the journal only accepts
// keys of the form ^[A-Z_][A-Z0-9_]*$.
ReplaceGroup func(group string) string
}
Options configure the Journal handler.