logger

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package logger emits stage-level diagnostic messages from CTK in two interchangeable formats:

  • text (default): human-friendly "[*] HH:MM:SS message" lines, identical to the legacy log.Logger output that the rest of the codebase already produces.
  • json: one JSON object per line, suitable for SIEM ingestion. Every record carries any attributes attached via SetGlobalAttrs (run_id, scenario, account, region, ...) so detection engineers can correlate CTK validation actions with downstream telemetry.

The active format is selected by `common.log_format` in config.yaml and applied during runner.InitConfig.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Attrs added in v0.2.7

func Attrs(kv ...any) []slog.Attr

Attrs converts alternating key / value pairs into a slog.Attr slice for SetGlobalAttrs convenience. Panics on odd argument count or non-string keys (matches slog's own contract).

func Error

func Error(v ...interface{})

Error emits an error record. Always written to the stderr writer.

func Info

func Info(v ...interface{})

Info emits a stage-level record. Suppressed when debug is off.

func IsDebug added in v0.2.7

func IsDebug() bool

IsDebug reports whether Info-level emission is currently enabled.

func SetDebug added in v0.2.0

func SetDebug(enabled bool)

SetDebug toggles whether Info-level records are emitted (legacy semantic).

func SetFormat added in v0.2.7

func SetFormat(f Format)

SetFormat switches the active output handler. Unknown values fall back to text and emit a warning so a typo in config.yaml degrades safely.

func SetGlobalAttrs added in v0.2.7

func SetGlobalAttrs(attrs ...slog.Attr)

SetGlobalAttrs replaces the slice of attributes attached to every emitted record. The headless layer pins run_id / provider / account / region here so JSON output gets a stable correlation envelope and text output gets trailing `key=value` hints.

Pass no arguments to clear.

func SetOutput added in v0.2.0

func SetOutput(w io.Writer)

SetOutput overrides both stdout and stderr to the same writer. Passing nil restores os.Stdout / os.Stderr (preserves legacy behavior).

func SetOutputs added in v0.2.0

func SetOutputs(stdout, stderr io.Writer)

SetOutputs separately overrides stdout and stderr. Either argument may be nil to fall back to OS defaults.

func Warning

func Warning(v ...interface{})

Warning emits a notable-but-non-fatal record.

Types

type Format added in v0.2.7

type Format string

Format selects the output handler.

const (
	FormatText Format = "text"
	FormatJSON Format = "json"
)

func CurrentFormat added in v0.2.7

func CurrentFormat() Format

CurrentFormat reports the currently active output format.

Jump to

Keyboard shortcuts

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