logging

package
v0.9.13 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Classify

func Classify(msg string) log.Level

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

func Component(root *log.Logger, name, level string) *log.Logger

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

func Logf(l *log.Logger) func(format string, v ...any)

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

func New(w io.Writer, level, format string) *log.Logger

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

func NewTee(term, file io.Writer, level, format string) *log.Logger

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

func ParseLevel(s string) log.Level

ParseLevel reads a level name; anything else is info.

func Writer added in v0.9.5

func Writer(l *log.Logger, level log.Level) io.Writer

Writer is l as an io.Writer that logs each line written to it at level, for code that prints its lines rather than logging them.

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.

func To added in v0.9.5

func To(l *log.Logger, logf func(format string, v ...any), kv ...any) Line

To is a Line carrying kv as its fields. logf, when set, wins over l: a package keeps a plain func only when it wasn't given a logger, or when a test has swapped its own in to read what was said.

func (Line) Debugf added in v0.9.5

func (p Line) Debugf(format string, v ...any)

func (Line) Errorf added in v0.9.5

func (p Line) Errorf(format string, v ...any)

func (Line) Infof added in v0.9.5

func (p Line) Infof(format string, v ...any)

func (Line) Warnf added in v0.9.5

func (p Line) Warnf(format string, v ...any)

func (Line) With added in v0.9.5

func (p Line) With(kv ...any) Line

With adds fields.

Jump to

Keyboard shortcuts

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