slogjournal

package module
v0.0.0-...-c1b76ca Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2025 License: BSD-3-Clause Imports: 16 Imported by: 0

README

slog: Systemd journal handler

[!CAUTION] This is pre-release software. No releases have been tagged yet.

Documentation

Index

Constants

View Source
const (
	LevelNotice slog.Level = 1

	LevelCritical  slog.Level = slog.LevelError + 1
	LevelAlert     slog.Level = slog.LevelError + 2
	LevelEmergency slog.Level = slog.LevelError + 3
)

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. variable names must be in uppercase and consist only of characters, numbers and underscores, and may not begin with an underscore.

func NewHandler

func NewHandler(opts *Options) (*Handler, error)

func (*Handler) Enabled

func (h *Handler) Enabled(_ context.Context, level slog.Level) bool

Enabled implements slog.Handler.

func (*Handler) Handle

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

Handle handles the Record. It will only be called when Enabled returns true. The Context argument is as for Enabled. It is present solely to provide Handlers access to the context's values. Canceling the context should not affect record processing. (Among other things, log messages may be necessary to debug a cancellation-related problem.)

Handle methods that produce output should observe the following rules:

  • If r.Time is the zero time, ignore the time.
  • If r.PC is zero, ignore it.
  • Attr's values should be resolved.
  • If an Attr's key and value are both the zero value, ignore the Attr. This can be tested with attr.Equal(Attr{}).
  • If a group's key is empty, inline the group's Attrs.
  • If a group has no Attrs (even if it has a non-empty key), ignore it.

func (*Handler) WithAttrs

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

WithAttrs implements slog.Handler.

func (*Handler) WithGroup

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

WithGroup implements slog.Handler.

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
	// variables that are uppercase and consist only of characters, numbers and
	// underscores, and may not begin with an underscore.
	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
	// variables that are uppercase and consist only of characters, numbers and
	// underscores, and may not begin with an underscore.
	ReplaceGroup func(group string) string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL