logging

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package logging provides structured logging with charmbracelet/log.

Index

Constants

View Source
const (
	VerboseLevel clog.Level = -2
	StatusLevel  clog.Level = 1
	ResultLevel  clog.Level = 2

	// DefaultLevel is the terminal log threshold in default mode (no flags).
	// At this level, Status (1) and Info (0) are suppressed on the terminal;
	// Result (2), DryRun (3), Warn (4), and Error (8) pass through.
	DefaultLevel clog.Level = 2
	DryRunLevel  clog.Level = 3

	// SilentLevel suppresses all terminal output. Used for --quiet mode.
	// No messages are emitted at this level; it is only a threshold.
	SilentLevel clog.Level = 12
)

Custom log levels that fill gaps in charmbracelet/log's default level scheme. Levels < WarnLevel go to stdout; levels >= WarnLevel go to stderr.

Variables

This section is empty.

Functions

func Close

func Close() error

Close closes the file logger. Call from main/deferred cleanup.

func Debug

func Debug(msg string, keyvals ...interface{})

Debug logs a debug message to stdout and file.

func Debugf

func Debugf(format string, args ...interface{})

Debugf logs a formatted debug message.

func DryRun

func DryRun(msg string, keyvals ...interface{})

DryRun logs a dry-run message to stdout and file.

func DryRunf

func DryRunf(format string, args ...interface{})

DryRunf logs a formatted dry-run message.

func Error

func Error(msg string, keyvals ...interface{})

Error logs an error message to stderr and file.

func Errorf

func Errorf(format string, args ...interface{})

Errorf logs a formatted error message.

func GetLevel

func GetLevel() clog.Level

GetLevel returns the current terminal log level.

func Info

func Info(msg string, keyvals ...interface{})

Info logs an info message to stdout and file.

func Infof

func Infof(format string, args ...interface{})

Infof logs a formatted info message.

func Init

func Init(cfg *config.Config) error

Init creates all loggers but does NOT set the terminal log level. Terminal level must be set separately via SetLevel() after all flag resolution is complete. Called from cmd/root.go PersistentPreRunE.

func InitForTest

func InitForTest(stdout, stderr io.Writer)

InitForTest creates loggers writing to the provided writers for test use. File logging is disabled. This allows tests to capture log output. Call ResetForTest in t.Cleanup to restore default loggers after the test.

func ResetForTest

func ResetForTest()

ResetForTest restores loggers to default stdout/stderr writers. Use in t.Cleanup to prevent test logging state from leaking across tests.

func Result added in v0.8.0

func Result(msg string, keyvals ...interface{})

Result logs a result message to stdout and file.

func Resultf added in v0.8.0

func Resultf(format string, args ...interface{})

Resultf logs a formatted result message.

func SetColors

func SetColors(enabled bool)

SetColors configures whether terminal loggers use color output. When NO_COLOR is set, enabling colors is a no-op to honor the convention.

func SetLevel

func SetLevel(l clog.Level)

SetLevel adjusts the terminal loggers' level. The file logger stays at Debug. The stdout logger level is set to the given level. The stderr logger level is always max(level, WarnLevel).

func SetSensitiveEnvPrefixes

func SetSensitiveEnvPrefixes(prefixes []string)

SetSensitiveEnvPrefixes configures additional sensitive KEY prefixes that should be masked before writing to persistent file logs.

func Status

func Status(msg string, keyvals ...interface{})

Status logs a status message to stdout and file.

func StatusPrefix

func StatusPrefix() string

StatusPrefix returns the styled status prefix used by StatusLevel logs. The result is computed once and cached to avoid rebuilding the styles map on every status line render tick.

func Statusf

func Statusf(format string, args ...interface{})

Statusf logs a formatted status message.

func Verbose

func Verbose(msg string, keyvals ...interface{})

Verbose logs a verbose message to stdout and file.

func Verbosef

func Verbosef(format string, args ...interface{})

Verbosef logs a formatted verbose message.

func Warn

func Warn(msg string, keyvals ...interface{})

Warn logs a warning message to stderr and file.

func WarnFilef added in v0.8.0

func WarnFilef(format string, args ...interface{})

WarnFilef logs a formatted warning message to the file logger only. Use when a warning should be persisted without printing to terminal.

func Warnf

func Warnf(format string, args ...interface{})

Warnf logs a formatted warning message.

Types

This section is empty.

Jump to

Keyboard shortcuts

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