Documentation
¶
Overview ¶
Package logging builds PayCLI's slog logger.
Two rules shape it:
- The destination is INJECTED. Only internal/cli/app.go may touch the process's standard streams (§3.1), so a logger is constructed with an io.Writer and every log line a command produces is capturable by a test.
- Every attribute passes through internal/redact before it is formatted. `[logging] level = "debug"` / PAY_LOG_LEVEL=debug is the documented way to see what PayCLI sent, and the Authorization header is synthesised by the transport rather than read from configured headers, so the "configured headers are secret" rule never covered it (§5.3).
Index ¶
Constants ¶
View Source
const ( FormatText = "text" FormatJSON = "json" )
Format values for logging format / PAY_LOG_FORMAT.
View Source
const ( LevelDebug = "debug" LevelInfo = "info" LevelWarn = "warn" LevelError = "error" )
Level names for logging level / PAY_LOG_LEVEL.
Variables ¶
View Source
var ( Levels = []string{LevelDebug, LevelInfo, LevelWarn, LevelError} Formats = []string{FormatText, FormatJSON} )
Levels and Formats are the closed sets, for validation and help.
Functions ¶
func Discard ¶
Discard is a logger that writes nothing. Packages take a *slog.Logger rather than reaching for slog.Default, so tests hand them this.
func New ¶
New builds the logger. It never returns nil: an invalid level or format degrades to info/text, because failing to log is not a reason to fail a command. Validate with ParseLevel / ParseFormat when you want the error.
func ParseFormat ¶
ParseFormat validates a log format name.
Types ¶
type Options ¶
type Options struct {
// Output is where log lines go. A nil Output discards everything, which is
// what tests and `--quiet` rely on.
Output io.Writer
// Level is one of Levels. Empty means info.
Level string
// Format is one of Formats. Empty means text.
Format string
// Verbose forces debug and Quiet forces error; Quiet wins, because
// --quiet is an explicit request for silence.
Verbose bool
Quiet bool
// Secrets are literal credential values to scrub from every line, in
// addition to the structural rules. The CLI passes the resolved API key
// and any minted JWT.
Secrets []string
// AddSource includes file:line. Off by default: it doubles the size of a
// debug transcript and helps nobody but a PayCLI developer.
AddSource bool
}
Options configures New.
Click to show internal directories.
Click to hide internal directories.