logging

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package logging configures ctm's structured diagnostic logger.

ctm has two distinct output channels. User-facing status messages (success, error, dim hints) go through internal/output.Printer on stdout and have always done so. Diagnostic lines — warnings about recoverable state issues, stripped unknown config keys, debug traces — go through log/slog on stderr, controlled by --log-level.

The two channels are deliberate. Anyone scripting against ctm pipes its stdout; filling stdout with diagnostic noise would break scripts. stderr is where an operator looks when something misbehaves.

At the default INFO level, stderr stays effectively silent for successful runs — only WARN/ERROR fire from normal paths.

Index

Constants

View Source
const (
	// EnvFormat selects the slog handler. "text" (default) or "json".
	EnvFormat = "CTM_LOG_FORMAT"
)

Env vars honoured by Setup.

Variables

This section is empty.

Functions

func ParseLevel

func ParseLevel(s string) (slog.Level, error)

ParseLevel turns a user-supplied level string into a slog.Level. Accepts the stdlib names case-insensitively; empty string → INFO.

func ResetForTest

func ResetForTest()

ResetForTest re-arms Setup so the next call takes effect. Tests only.

func Setup

func Setup(level string) error

Setup configures the default slog.Logger to write structured diagnostics to stderr at the given level. Parseable levels (case- insensitive): "debug", "info", "warn", "error". An empty string is treated as "info".

It is safe to call multiple times; only the first call has effect so that subcommands calling Setup in their own PreRun don't clobber a root-level configuration. Tests can bypass the once guard with ResetForTest.

Format defaults to text (human-readable). Set CTM_LOG_FORMAT=json to emit newline-delimited JSON suitable for log aggregators.

Types

This section is empty.

Jump to

Keyboard shortcuts

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