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](https://systemd.io/JOURNAL_NATIVE_PROTOCOL/). Journal only supports keys of the form ^[A-Z_][A-Z0-9_]*$. Any other keys will be silently dropped.
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.