journalwriter

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DontFallback = false

DontFallback disables printing failed logs to FallbackWriter (set FallbackWriter nil to disable completely)

View Source
var DontLogErrors = false

DontLogErrors disables printing errors to FallbackWriter

View Source
var ErrVarNameEmpty = errors.New("empty variable name")
View Source
var ErrVarNameInvalid = errors.New("variable name contains invalid characters")
View Source
var ErrVarNameUnderscore = errors.New("variable name begins with an underscore")
View Source
var FallbackWriter = os.Stderr

FallbackWriter is used when writing to journal fails

If nil, write fails will be silent.

Functions

func Enabled

func Enabled() bool

Enabled checks whether the local systemd journal is available for logging.

func GetJournalOrStderr

func GetJournalOrStderr(p Priority) io.Writer

GetJournalOrStderr checks if journal is enabled.

if not, returns os.Stderr

If p is zero, uses INFO level

func Print

func Print(priority Priority, format string, a ...interface{}) error

Print prints a message to the local systemd journal using Send().

func Send

func Send(message string, priority Priority, vars map[string]string) error

Send a message to the local systemd journal. vars is a map of journald fields to values. Fields must be composed of uppercase letters, numbers, and underscores, but must not start with an underscore. Within these restrictions, any arbitrary field name may be used. Some names have special significance: see the journalctl documentation (http://www.freedesktop.org/software/systemd/man/systemd.journal-fields.html) for more details. vars may be nil.

Types

type JournalWriter

type JournalWriter struct {
	Priority // default 0 is 'Emergency' level
}

JournalWriter writes to the systemd journal. If journal is not available, it falls back to FallbackWriter. It's an io.Writer, and log.SetOutput() can be used to set it as the default logger.

var Info = JournalWriter{journal.PriInfo} var Err = JournalWriter{journal.PriErr} var Debug = JournalWriter{journal.PriDebug} var Warning = JournalWriter{journal.PriWarning} var Emergency = JournalWriter{journal.PriEmerg} var Alert = JournalWriter{journal.PriAlert} var Critical = JournalWriter{journal.PriCrit} var Notice = JournalWriter{journal.PriNotice}

func (JournalWriter) Write

func (j JournalWriter) Write(b []byte) (int, error)

Write writes to the journal, falling back to stderr if journal is not available.

See DontLogErrors and DontFallback to change behavior when errors occur.

type Priority

type Priority int

Priority of a journal message

const (
	PriEmerg Priority = iota
	PriAlert
	PriCrit
	PriErr
	PriWarning
	PriNotice
	PriInfo
	PriDebug
)

Jump to

Keyboard shortcuts

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