debug

package
v0.2.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package debug provides structured debug logging for the StackEye CLI.

Debug logging is enabled via the --debug flag (shorthand for --v=6) or STACKEYE_DEBUG environment variable. Output is written to stderr to keep stdout clean for machine-parseable command output.

The package uses Go's log/slog for structured logging, matching the backend's logging approach. Verbosity levels follow kubectl conventions (0-10):

  • 0: Errors only (default, no debug output)
  • 1: Warnings
  • 2: Info messages
  • 3: Extended info (config/context details)
  • 4: Debug messages (internal flow)
  • 5: HTTP requests (method, URL, duration)
  • 6: HTTP responses (+ status code, body size) [--debug shorthand]
  • 7: Request headers (redacted)
  • 8: Response headers
  • 9: Full bodies (truncated at 10KB)
  • 10: Trace (curl equivalent, timing breakdown)

Usage:

// In root.go init():
debug.SetVerbosityGetter(GetVerbosity)

// In any package:
debug.Log(3, "loading config", "path", configPath)
debug.Logf(4, "resolved context: %s", contextName)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigError

func ConfigError(path string, err error)

ConfigError logs a configuration loading error. Emits at verbosity level 1 (warnings).

func ConfigLoaded

func ConfigLoaded(path string, context string)

ConfigLoaded logs that configuration was successfully loaded. Emits at verbosity level 3 (extended info).

func Enabled

func Enabled(level int) bool

Enabled returns true if debug output is active at the given verbosity level.

func EnvOverride

func EnvOverride(envVar string, value string)

EnvOverride logs when an environment variable overrides a config value. Values for env vars ending in _KEY, _SECRET, _TOKEN, or _PASSWORD are redacted. Emits at verbosity level 3 (extended info).

func Log

func Log(level int, msg string, args ...any)

Log emits a structured debug message if the current verbosity is >= level. Key-value pairs are passed as slog attributes.

Example:

debug.Log(3, "config loaded", "path", "/home/user/.config/stackeye/config.yaml")

func Logf

func Logf(level int, format string, args ...any)

Logf emits a formatted debug message if the current verbosity is >= level.

Example:

debug.Logf(4, "resolved context: %s", contextName)

func SetVerbosityGetter

func SetVerbosityGetter(getter func() int)

SetVerbosityGetter sets the function used to retrieve the verbosity level. This should be called during CLI initialization (root.go init).

func SetWriter

func SetWriter(w io.Writer)

SetWriter overrides the output writer (default: os.Stderr). Intended for testing.

Types

This section is empty.

Jump to

Keyboard shortcuts

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