Documentation
¶
Overview ¶
Package logging is the daemon's own log: leveled, timestamped lines through charmbracelet/log, in text for a person (coloured on a terminal) or json or logfmt for a collector.
serve makes one logger and hands each part of the daemon its own Component of it, which the part logs through at real levels with fields, by way of a Line. A part also still takes a plain func(format string, v ...any), which its tests and older callers use; Logf adapts a logger to that for whatever hasn't got levels of its own, choosing each line's level from its wording.
Index ¶
- func Classify(msg string) log.Level
- func Component(root *log.Logger, name, level string) *log.Logger
- func Logf(l *log.Logger) func(format string, v ...any)
- func New(w io.Writer, level, format string) *log.Logger
- func NewTee(term, file io.Writer, level, format string) *log.Logger
- func ParseLevel(s string) log.Level
- func Writer(l *log.Logger, level log.Level) io.Writer
- type Line
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Classify ¶
Classify guesses a line's level from its wording. The daemon's lines were written for a person, without levels, and saying something failed is how they mark trouble: an error is something that didn't happen, a warning is something that went ahead in a lesser way, and the rest is information.
func Component ¶ added in v0.9.5
Component is root's logger for one part of the daemon: its lines carry name as their prefix, and it logs at level ("debug", "info", "warn" or "error"), so one part can be turned up without the rest.
func Logf ¶
Logf adapts l to the func(format, v...) the daemon's packages log through. Each line's level is read from its wording (see Classify), and the "outpost: " every line used to start with is dropped, since the logger's prefix now says where a line came from.
func New ¶
New is a logger writing to w at level ("debug", "info", "warn" or "error") in format ("text", "json" or "logfmt"). Unknown values fall back to info and text; config validation is where they are refused.
func NewTee ¶ added in v0.9.5
NewTee is New writing every line to both term, the stdout or stderr that a person or launchd or systemd reads, and file, the log the daemon keeps itself. The colour term would get on a terminal is kept for term and left out of file. A nil file is New on term alone.
func ParseLevel ¶
ParseLevel reads a level name; anything else is info.
Types ¶
type Line ¶ added in v0.9.5
type Line struct {
// contains filtered or unexported fields
}
Line is one package's way to log a line at a level, with fields. It goes to a *log.Logger when the package was handed one, which is how the daemon runs. A package handed only a plain func(format, v...) instead, as its older callers and its tests do, gets every line there with its format and arguments untouched and its level and fields dropped, exactly as before packages had levels.