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 ¶
- func ConfigError(path string, err error)
- func ConfigLoaded(path string, context string)
- func Enabled(level int) bool
- func EnvOverride(envVar string, value string)
- func Log(level int, msg string, args ...any)
- func Logf(level int, format string, args ...any)
- func SetVerbosityGetter(getter func() int)
- func SetWriter(w io.Writer)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfigError ¶
ConfigError logs a configuration loading error. Emits at verbosity level 1 (warnings).
func ConfigLoaded ¶
ConfigLoaded logs that configuration was successfully loaded. Emits at verbosity level 3 (extended info).
func EnvOverride ¶
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 ¶
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 ¶
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).
Types ¶
This section is empty.