logging

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// LogFile is the BOXER_LOG_FILE env-var spec.
	LogFile = env.NewString(env.Spec{
		Name:        "BOXER_LOG_FILE",
		Description: "path to the log file; empty or \"-\" routes to stderr",
		Category:    env.CategoryObservability,
		CliFlagName: "logFile",
	})

	// LogCaller is the BOXER_LOG_CALLER env-var spec.
	LogCaller = env.NewBool(env.Spec{
		Name:        "BOXER_LOG_CALLER",
		Description: "include caller file:line in log records",
		Category:    env.CategoryObservability,
		CliFlagName: "logCaller",
	})

	// LogOsHostOnStart is the BOXER_LOG_OS_HOST_ON_START env-var spec.
	LogOsHostOnStart = env.NewBool(env.Spec{
		Name:        "BOXER_LOG_OS_HOST_ON_START",
		Description: "log the host name on application startup",
		Category:    env.CategoryObservability,
		CliFlagName: "logOsHostOnStart",
	})

	// LogOsArgsOnStart is the BOXER_LOG_OS_ARGS_ON_START env-var spec.
	LogOsArgsOnStart = env.NewBool(env.Spec{
		Name:        "BOXER_LOG_OS_ARGS_ON_START",
		Description: "log os.Args on application startup",
		Category:    env.CategoryObservability,
		CliFlagName: "logOsArgsOnStart",
	})

	// LogOsPidOnStart is the BOXER_LOG_OS_PID_ON_START env-var spec.
	LogOsPidOnStart = env.NewBool(env.Spec{
		Name:        "BOXER_LOG_OS_PID_ON_START",
		Description: "log the OS process id on application startup",
		Category:    env.CategoryObservability,
		CliFlagName: "logOsPidOnStart",
	})

	// LogVcsRevisionOnStart is the BOXER_LOG_VCS_REVISION_ON_START env-var spec.
	LogVcsRevisionOnStart = env.NewBool(env.Spec{
		Name:        "BOXER_LOG_VCS_REVISION_ON_START",
		Description: "log the VCS revision on application startup",
		Category:    env.CategoryObservability,
		CliFlagName: "logVcsRevisionOnStart",
	})

	// LogModuleInfoOnStart is the BOXER_LOG_MODULE_INFO_ON_START env-var spec.
	// Renamed from BOXER_LOG_MODULE_INFO_IN_START in passing per ADR-0009 §6
	// (the four sibling flags use _ON_START).
	LogModuleInfoOnStart = env.NewBool(env.Spec{
		Name:        "BOXER_LOG_MODULE_INFO_ON_START",
		Description: "log the Go module info on application startup",
		Category:    env.CategoryObservability,
		CliFlagName: "logModuleInfoOnStart",
	})

	// LogCorrelationId is the BOXER_LOG_CORRELATION_ID env-var spec.
	LogCorrelationId = env.NewString(env.Spec{
		Name:        "BOXER_LOG_CORRELATION_ID",
		Description: "correlation id for log records; empty seeds a nanoid(21)",
		Category:    env.CategoryObservability,
		CliFlagName: "logCorrelationId",
	})

	// LogLevel is the BOXER_LOG_LEVEL env-var spec.
	LogLevel = env.NewCategorialString(env.Spec{
		Name:        "BOXER_LOG_LEVEL",
		Default:     "info",
		Description: "zerolog level",
		Category:    env.CategoryObservability,
		CliFlagName: "logLevel",
	}, []string{"trace", "debug", "info", "warn", "error", "fatal", "panic"})

	// LogFormat is the BOXER_LOG_FORMAT env-var spec.
	LogFormat = env.NewCategorialString(env.Spec{
		Name:        "BOXER_LOG_FORMAT",
		Default:     "json",
		Description: "log output format",
		Category:    env.CategoryObservability,
		CliFlagName: "logFormat",
	}, []string{"default", "console", "diag", "godump", "json", "json-indent", "cbor"})

	// LogColor is the BOXER_LOG_COLOR env-var spec. Honored by the
	// console format. An explicit value wins; otherwise color auto-detects
	// from whether stderr is a terminal, and a --logFile destination
	// always disables it (ANSI escapes in a log file are noise).
	LogColor = env.NewBool(env.Spec{
		Name:        "BOXER_LOG_COLOR",
		Default:     "true",
		Description: "colorize console log output (auto-detects TTY when unset; off for file destinations)",
		Category:    env.CategoryObservability,
		CliFlagName: "logColor",
	})
)

Environment variable declarations for the logging subsystem. Registered with the boxer-wide registry per ADR-0009.

View Source
var LoggingFlags = []cli.Flag{
	LogFile.AsCliFlag(),
	LogCaller.AsCliFlag(),
	LogOsHostOnStart.AsCliFlag(),
	LogOsArgsOnStart.AsCliFlag(),
	LogOsPidOnStart.AsCliFlag(),
	LogVcsRevisionOnStart.AsCliFlag(),
	LogModuleInfoOnStart.AsCliFlag(),
	LogCorrelationId.AsCliFlag(),
	LogLevel.AsCliFlag(),
	LogFormat.AsCliFlag(),
	LogColor.AsCliFlag(),
}
View Source
var PackageProps = packageprops.Props{
	WASMWASI:         packageprops.WASMCompiles,
	WASMJS:           packageprops.WASMCompiles,
	WASMFreestanding: packageprops.WASMCompiles,
}

PackageProps records this package's curated properties (ADR-0080). Seeded by `boxer code analysis golang wasmsurvey props generate`; curate by hand. The same group's `props verify` reconciles it.

Functions

func Apply

func Apply(ctx *cli.Context) (err error)

Apply configures zerolog from the parsed cli.Context. Wire it as cli.App.Before so it runs for every invocation regardless of which flags the user supplied — flag-level Action closures only fire when the flag is explicitly set, which silently swallowed startup-info logging before this refactor.

Order of effects: writer → global level → caller frame → correlation id → "application startup" record. The startup record is emitted only when at least one of the host/pid/args/vcs/module flags is set.

func NewConsoleWriter

func NewConsoleWriter(out io.Writer, noColor bool) (cw zerolog.ConsoleWriter, err error)

NewConsoleWriter builds the human-readable zerolog ConsoleWriter used for --logFormat=console. It is the single source of truth for that writer's configuration: every console writer in the process — notably the facts-log-bridge operator passthrough (thestack/cmd/imzero2) — must obtain its writer here rather than hand-rolling a zerolog.ConsoleWriter.

Why a shared constructor and not a copied struct literal: SetupConsoleLogger installs a process-global InterfaceMarshalFunc (embeddAsCbor) that CBOR-embeds every value zerolog's console writer routes through the marshaler — which, per zerolog console.go writeFields, is every field that is neither a string nor a json.Number (bool, nil, slices, structs via .Interface). Only the FormatFieldValue installed here expands those embedded `data:application/cbor;base64,…` blobs back to a scalar. A console writer that omits FormatFieldValue therefore prints the raw blob for every bool. The marshal half and the format half are two ends of one codec; this constructor keeps them coupled so they cannot drift.

func NewFormatWriter

func NewFormatWriter(format string, out io.Writer, noColor bool) (w io.Writer, err error)

NewFormatWriter builds the operator-facing writer for `format`, wrapping `out`. It is the single source of truth for translating --logFormat into a concrete io.Writer, shared by applyWriter (the primary logger) and — via OperatorWriter — the facts-log-bridge passthrough, so both render identically and honor --logFile/--logColor.

Each non-raw format writer decodes the zerolog wire and reformats it, which is exactly what lets the bridge reuse the same writer over its own wire payload. "cbor" and "default" return `out` unchanged (raw wire bytes); "cbor" additionally requires the binary_log build tag, which the caller verifies (applyWriter calls checkZeroLogCborBuild). The console writer carries the CBOR field-expansion formatter (NewConsoleWriter); installing its process-global marshalers is the caller's job (installConsoleCborMarshalers).

func OperatorWriter

func OperatorWriter() io.Writer

OperatorWriter returns the writer Apply configured for operator-facing output: the same --logFormat, --logFile destination, and --logColor as the primary logger. The facts-log-bridge reuses it as its passthrough so the operator stream honors the full logger config instead of re-deriving a stderr console writer (which silently dropped --logFile and every non-console format). Returns nil if Apply has not run.

func SetupCborDiagLogger

func SetupCborDiagLogger(w io.StringWriter) (err error)

func SetupConsoleLogger

func SetupConsoleLogger(w io.Writer) (err error)

func SetupGoDumpLogger

func SetupGoDumpLogger(w io.Writer) (err error)

func SetupJsonIndentLogger

func SetupJsonIndentLogger(w io.Writer) (err error)

func SetupJsonLogger

func SetupJsonLogger(w io.Writer) (err error)

func UnmarshallZerologMsg

func UnmarshallZerologMsg(msg []byte) (v any, err error)

Types

type CborDiagLogger

type CborDiagLogger struct {
	Out io.StringWriter
}

func NewCborDiagLogger

func NewCborDiagLogger(out io.StringWriter) *CborDiagLogger

func (*CborDiagLogger) Write

func (inst *CborDiagLogger) Write(p []byte) (n int, err error)

type CborSpewLogger

type CborSpewLogger struct {
	Out io.Writer
	// contains filtered or unexported fields
}

func NewCborGodumpLogger

func NewCborGodumpLogger(out io.Writer) *CborSpewLogger

func (*CborSpewLogger) Write

func (inst *CborSpewLogger) Write(p []byte) (n int, err error)

type JsonIndentLogger

type JsonIndentLogger struct {
	Out io.Writer

	Prefix string
	Indent string
	// contains filtered or unexported fields
}

func NewJsonIndentLogger

func NewJsonIndentLogger(out io.Writer) *JsonIndentLogger

func (*JsonIndentLogger) Write

func (inst *JsonIndentLogger) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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