log

package
v1.2.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: MPL-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LevelTrace = 3
	LevelDebug = 2
	LevelInfo  = 1
	LevelWarn  = 1
	LevelError = 0
	LevelFatal = 0
)

Verbosity levels mapped from CLI flags.

Variables

This section is empty.

Functions

func AddSink added in v1.3.1

func AddSink(w io.Writer) (remove func())

AddSink attaches w as an additional destination for log output for the duration of the returned remove func. Each line of log output is written to w in addition to stderr. Multiple concurrent sinks are supported.

w must be safe for concurrent Write calls — AddSink does not serialize writes to a single sink. io.Pipe writers and io.MultiWriter wrapping pre-serialized destinations are both fine; bare bytes.Buffer is not.

func Debug added in v1.1.0

func Debug(args ...any)

func DebugEnabled added in v1.1.0

func DebugEnabled() bool

DebugEnabled reports whether debug-level messages are currently logged.

func Debugf added in v1.1.0

func Debugf(format string, args ...any)

func Debugw added in v1.1.0

func Debugw(msg string, keysAndValues ...any)

func Error added in v1.1.0

func Error(args ...any)

func Errorf added in v1.1.0

func Errorf(format string, args ...any)

func Errorw added in v1.1.0

func Errorw(msg string, keysAndValues ...any)

func Fatal added in v1.1.0

func Fatal(args ...any)

func Fatalf added in v1.1.0

func Fatalf(format string, args ...any)

func Info added in v1.1.0

func Info(args ...any)

func Infof added in v1.1.0

func Infof(format string, args ...any)

func Infow added in v1.1.0

func Infow(msg string, keysAndValues ...any)

func Init added in v1.1.0

func Init(cfg Config)

Init configures the global logger. Called once in root command PersistentPreRunE.

func InitTest added in v1.1.0

func InitTest(t testing.TB)

InitTest replaces the package-level logger with a test logger. Log output is captured by t.Log() and only shown on test failure.

func InitTestObserved added in v1.1.0

func InitTestObserved(t testing.TB, level zapcore.Level) *observer.ObservedLogs

InitTestObserved replaces the package-level logger with an observable logger at the given level. The returned ObservedLogs can be used to assert that specific log messages were emitted.

func JSONError added in v1.3.1

func JSONError(cliErr *cliErrors.CLIError)

JSONError writes a single structured zap entry carrying a *CLIError under the "cliError" field. The desktop IPC layer parses this field by name.

The top-level "msg" is set to the original error chain (when available) so that log consumers grepping the textual message still see the underlying cause. The friendly, user-facing summary remains in cliError.message and is what the desktop UI surfaces.

func LevelString added in v1.1.0

func LevelString() string

LevelString returns the lowest enabled log level as a lowercase string (e.g. "debug", "info", "warn", "error", "fatal").

func LogrSink added in v1.1.0

func LogrSink() logr.LogSink

LogrSink returns a logr.LogSink for Kubernetes client-go compatibility.

func PipeJSONStream

func PipeJSONStream() (io.WriteCloser, chan struct{})

func QuestionDefault added in v1.1.0

func QuestionDefault(opts *survey.QuestionOptions) (string, error)

QuestionDefault asks a question using the default survey implementation.

func ReadJSONStream

func ReadJSONStream(reader io.Reader)

func Sync added in v1.1.0

func Sync() error

Sync flushes any buffered log entries. Call before process exit.

func Underlying added in v1.1.0

func Underlying() *zap.Logger

Underlying returns the raw *zap.Logger for advanced use cases.

func VerbosityToLevel added in v1.1.0

func VerbosityToLevel(verbosity int) zapcore.Level

VerbosityToLevel converts a -v count (0-3) to a zapcore.Level. 0 = error+fatal only, 1 = +warn+info, 2 = +debug, 3 = trace (mapped to zap Debug-1).

func Warn added in v1.1.0

func Warn(args ...any)

func Warnf added in v1.1.0

func Warnf(format string, args ...any)

func Warnw added in v1.1.0

func Warnw(msg string, keysAndValues ...any)

func Writer added in v1.1.0

func Writer(level int) io.WriteCloser

Writer returns an io.WriteCloser that writes each line as a log entry at the given level. Level uses the package constants: LevelInfo, LevelDebug, etc.

Types

type Config added in v1.1.0

type Config struct {
	Verbosity int    // 0=error, 1=info+warn, 2=debug, 3=trace
	Quiet     bool   // fatal only
	Debug     bool   // backwards compat, equivalent to Verbosity=2
	Format    string // "text", "json", "logfmt"
}

Config holds logger configuration parsed from CLI flags.

Jump to

Keyboard shortcuts

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