Documentation
¶
Overview ¶
Package logger provides the dhctl logging foundation built on log/slog. It exposes a dual-sink handler (file always; terminal for ShowInCompacted()-tagged records), a RunProcess helper for process blocks, silent/buffer loggers, an io.Writer adapter, klog and shell-operator bindings, a root-logger constructor, and the single LibdhctlAdapter bridging slog to lib-connection's logger interface.
Index ¶
- Constants
- func BadgeFailed() slog.Attr
- func BadgeSuccess() slog.Attr
- func BadgeWarning() slog.Attr
- func Banner() slog.Attr
- func BindKlog(l *slog.Logger)
- func BindShellOperator(l *slog.Logger, debug bool)
- func ConnectionString() slog.Attr
- func Discard() *slog.Logger
- func Fail(ctx context.Context, l *slog.Logger, msg string)
- func FailRetry(ctx context.Context, l *slog.Logger, msg string)
- func FileOnly() slog.Attr
- func FinishProgress(ctx context.Context, l *slog.Logger)
- func FromContext(ctx context.Context) *slog.Logger
- func JSON(ctx context.Context, l *slog.Logger, data []byte)
- func NewBufferLogger(w io.Writer) *slog.Logger
- func NewRoot(opts Options) *slog.Logger
- func NewStreamLogger(w io.Writer) *slog.Logger
- func PauseProgress(ctx context.Context, l *slog.Logger)
- func PrintBanner(ctx context.Context)
- func Progress(ctx context.Context, l *slog.Logger, frac float64, title string)
- func RestoreTerminal()
- func ResumeProgress(ctx context.Context, l *slog.Logger)
- func RunProcess(ctx context.Context, l *slog.Logger, name string, ...) error
- func Sanitize(_ []string, attr slog.Attr) slog.Attr
- func ShowInCompacted() slog.Attr
- func StartProgress(ctx context.Context, l *slog.Logger, name string)
- func Success(ctx context.Context, l *slog.Logger, msg string)
- func ToContext(ctx context.Context, l *slog.Logger) context.Context
- type Adapter
- func (a *Adapter) BufferLogger(buffer *bytes.Buffer) libdhctl_log.Logger
- func (a *Adapter) DebugF(format string, args ...interface{})
- func (a *Adapter) DebugFWithoutLn(format string, args ...interface{})
- func (a *Adapter) DebugLn(args ...interface{})
- func (a *Adapter) ErrorF(format string, args ...interface{})
- func (a *Adapter) ErrorFWithoutLn(format string, args ...interface{})
- func (a *Adapter) ErrorLn(args ...interface{})
- func (a *Adapter) Fail(msg string)
- func (a *Adapter) FailRetry(msg string)
- func (a *Adapter) FlushAndClose() error
- func (a *Adapter) InfoF(format string, args ...interface{})
- func (a *Adapter) InfoFWithoutLn(format string, args ...interface{})
- func (a *Adapter) InfoLn(args ...interface{})
- func (a *Adapter) JSON(data []byte)
- func (a *Adapter) Process(p libdhctl_log.Process, t string, run func() error) error
- func (a *Adapter) ProcessLogger() libdhctl_log.ProcessLogger
- func (a *Adapter) SilentLogger() *libdhctl_log.SilentLogger
- func (a *Adapter) Success(msg string)
- func (a *Adapter) WarnF(format string, args ...interface{})
- func (a *Adapter) WarnFWithoutLn(format string, args ...interface{})
- func (a *Adapter) WarnLn(args ...interface{})
- func (a *Adapter) Warning(msg string)
- func (a *Adapter) WithContext(ctx context.Context) *Adapter
- func (a *Adapter) Write(p []byte) (int, error)
- type AdapterProcessLogger
- type LineWriter
- type Options
- type TerminalUIHandler
- func (h *TerminalUIHandler) Enabled(_ context.Context, level slog.Level) bool
- func (h *TerminalUIHandler) Handle(ctx context.Context, r slog.Record) error
- func (h *TerminalUIHandler) RestoreTerminal()
- func (h *TerminalUIHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (h *TerminalUIHandler) WithGroup(name string) slog.Handler
Constants ¶
const DeckhouseBanner = "" +
`========================================================================================
_____ _ _ ______ _ _____
(____ \ | | | | / _____) | (_____)
_ \ \ ____ ____| | _| | _ ___ _ _ ___ ____ | / ____ ____ _ | | _
| | | / _ ) ___) | / ) || \ / _ \| | | |/___)/ _ ) | | / _ | _ \ / || | | |
| |__/ ( (/ ( (___| |< (| | | | |_| | |_| |___ ( (/ / | \____( ( | | | | ( (_| |_| |_
|_____/ \____)____)_| \_)_| |_|\___/ \____(___/ \____) \______)_||_|_| |_|\____(_____)
========================================================================================`
DeckhouseBanner is the startup ASCII banner shown at the top of dhctl operations (bootstrap, destroy, ...). Kept here so every operation shares one source of truth.
Variables ¶
This section is empty.
Functions ¶
func BadgeFailed ¶
func BadgeSuccess ¶
BadgeSuccess/BadgeFailed/BadgeWarning return the attribute tagging a record to render with the matching colored status badge. Pair with ShowInCompacted() so the record reaches the compact view.
func BadgeWarning ¶
func Banner ¶
Banner marks a record whose message is the startup ASCII banner. The terminal UI pins it at the top of the live canvas instead of scrolling it as a log line.
func BindKlog ¶
BindKlog routes k8s.io/klog/v2 output into the given slog logger. Sensitive-keyword sanitization happens in the handler (via Sanitize), so klog output is filtered too.
func BindShellOperator ¶
BindShellOperator routes shell-operator's default logger output into the given slog logger.
shell-operator uses github.com/deckhouse/deckhouse/pkg/log as its logger and emits klog/internal lines through it. When debug is false, shell-operator is muted (fatal level); when debug is true, its level is lowered to debug and its output is captured into l via a file-only LineWriter, so each emitted line becomes an slog record that enriches the .log file but never reaches the terminal. That keeps the terminal identical with or without DHCTL_DEBUG.
Note: this mutates the shell-operator global default logger (shlog.Default()).
func ConnectionString ¶
ConnectionString marks a record whose message is the SSH connection string. The terminal UI pins it as a distinct milestone so it stays visible and is included in the closing summary.
func Discard ¶
Discard returns a logger that drops every record. Replaces NewSilentLogger / NewDummyLogger.
func FileOnly ¶
FileOnly tags a record to stay file-only on the terminal: suppressed in the compact view regardless of level, shown only with -v.
func FinishProgress ¶
FinishProgress closes the active terminal progress session.
func FromContext ¶
FromContext returns the logger carried by ctx, or slog.Default() if none is present. It never returns nil.
func NewBufferLogger ¶
NewBufferLogger returns a logger writing every record to w as text. Replaces BufferLogger.
func NewRoot ¶
NewRoot builds the application root logger. Replaces InitLogger / InitLoggerWithOptions / WrapWithTeeLogger / NewLogToFile from the old package.
func NewStreamLogger ¶
NewStreamLogger returns a logger that renders the compact UI (process boxes framed with ┌/│/└, milestones, banner, connection string) as plain ANSI-free lines to w — the format the commander client expects, instead of raw slog text. It backs the gRPC client-stream logger.
Unlike NewRoot it does not register a global rootHandler, so it is safe to build per request and for concurrent operations. There is no file (JSON) sink: w is a server LogWriter that already logs every rendered line to the server slog and forwards it to the client. verbose forwards every Info+ detail line (e.g. terraform output) to the renderer; DEBUG never reaches the terminal sink.
func PauseProgress ¶
PauseProgress stops rendering the progress session (e.g. around interactive input).
func PrintBanner ¶
PrintBanner logs the Deckhouse ASCII banner. Tagged Banner(): the terminal UI pins it at the top of the live canvas instead of scrolling it as an ordinary log line.
func RestoreTerminal ¶
func RestoreTerminal()
RestoreTerminal leaves the alternate screen if the current root handler is using an interactive Block. Safe to call before NewRoot, multiple times, and after the Block has already been finished. Designed as a no-arg shutdown hook / defer (see cmd/dhctl/main.go).
func ResumeProgress ¶
ResumeProgress restarts rendering the progress session after a pause.
func RunProcess ¶
func RunProcess(ctx context.Context, l *slog.Logger, name string, fn func(context.Context) error) error
RunProcess wraps fn with process start/end (or start/fail) marker records, so the handler can render a process block. The returned error is fn's error, unchanged.
func Sanitize ¶
Sanitize is a slog.ReplaceAttr function. It scans string values for sensitive keywords and replaces matches with [FILTERED - ...]. Recursively processes groups. Skips control attributes (time, level, source, renderer markers). Idempotent - already filtered values pass through unchanged.
func ShowInCompacted ¶
ShowInCompacted returns the attribute that tags a record to appear in the compact view.
func StartProgress ¶
StartProgress opens a terminal progress session named name.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter wraps slog.Logger and implements libdhctl_log.LoggerProvider and its internal interfaces.
func NewAdapter ¶
NewAdapter creates a new logger adapter.
func NewLibdhctlAdapter ¶
NewLibdhctlAdapter is the canonical constructor used at the lib-connection boundary. It binds ctx so every record the adapter emits carries the caller's context (cancellation, trace span, context values) instead of a detached background one.
func (*Adapter) BufferLogger ¶
func (a *Adapter) BufferLogger(buffer *bytes.Buffer) libdhctl_log.Logger
BufferLogger returns an Adapter writing every record to buffer as sanitized JSON. The buffer is never a terminal, so this is a plain file-style sink (no progress UI).
func (*Adapter) DebugFWithoutLn ¶
func (*Adapter) ErrorFWithoutLn ¶
func (*Adapter) FlushAndClose ¶
FlushAndClose implements libdhctl_log.Logger.
func (*Adapter) InfoFWithoutLn ¶
func (*Adapter) ProcessLogger ¶
func (a *Adapter) ProcessLogger() libdhctl_log.ProcessLogger
ProcessLogger implements libdhctl_log.Logger by returning a ProcessLogger bound to this adapter.
func (*Adapter) SilentLogger ¶
func (a *Adapter) SilentLogger() *libdhctl_log.SilentLogger
func (*Adapter) Success ¶
Success and FailRetry are per-process / per-attempt lib-connection notices, emitted in bulk (each dependency check, each retry). They are NOT compact-tagged: they stay in the debug file and only surface with -v. Only successful PHASE transitions appear in the compact view (see pkg/operations/phases). FailRetry is retry noise — logged at Debug so a recovered retry stays quiet. Fail is a real failure: it surfaces by its Error level and renders the red FAILED badge.
func (*Adapter) WarnFWithoutLn ¶
func (*Adapter) WithContext ¶
WithContext returns a new Adapter with the given context.
type AdapterProcessLogger ¶
type AdapterProcessLogger struct {
// contains filtered or unexported fields
}
AdapterProcessLogger bridges lib-connection's ProcessLogger to the process-block markers the terminal handler renders (┌ … └), mirroring RunProcess.
func (*AdapterProcessLogger) ProcessEnd ¶
func (ap *AdapterProcessLogger) ProcessEnd()
func (*AdapterProcessLogger) ProcessFail ¶
func (ap *AdapterProcessLogger) ProcessFail()
func (*AdapterProcessLogger) ProcessStart ¶
func (ap *AdapterProcessLogger) ProcessStart(name string)
func (*AdapterProcessLogger) ProcessStep ¶
func (ap *AdapterProcessLogger) ProcessStep(name string)
type LineWriter ¶
type LineWriter struct {
// contains filtered or unexported fields
}
LineWriter is an io.Writer that turns each newline-terminated line into an Info record. Used to pipe external command (exec) output into the logger. Replaces logger-as-io.Writer. When fileOnly is set, each line is tagged FileOnly so it lands in the debug file but never the compact terminal.
func NewLineWriter ¶
func NewLineWriter(l *slog.Logger) *LineWriter
NewLineWriter returns a LineWriter emitting each line as a plain Info record.
type Options ¶
type Options struct {
FileWriter io.Writer // required; always-on sink
TTYWriter io.Writer // optional; terminal sink for ShowInCompacted()-tagged records
IsTTY bool // whether TTYWriter is a terminal (enables the terminal sink at all)
// Interactive enables the pinned pterm progress bar. False (e.g. with -v) keeps the terminal
// sink but renders plain linear lines with no pinned block.
Interactive bool
// Verbose (-v) shows every Info+ record on the terminal, not just the curated compact output.
Verbose bool
}
Options configures the root logger.
- FileWriter receives every record (the always-on debug-file sink). Required.
- TTYWriter, when non-nil and IsTTY is true, receives ShowInCompacted()-tagged records (the terminal).
type TerminalUIHandler ¶
type TerminalUIHandler struct {
// contains filtered or unexported fields
}
TerminalUIHandler is a dual-sink slog.Handler.
- File sink: receives every enabled record (JSON).
- TTY sink: receives only records tagged with ShowInCompacted(), and only when stdout is a terminal.
func (*TerminalUIHandler) RestoreTerminal ¶
func (h *TerminalUIHandler) RestoreTerminal()
RestoreTerminal leaves the alternate screen if an interactive Block is active. Safe to call multiple times and when no Block exists.