logging

package
v1.160.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Overview

============================================================================= NFTBan v1.73 - Installer Dual Logger ============================================================================= SPDX-License-Identifier: MPL-2.0 meta:name="installer-logger" meta:type="lib" meta:owner="Antonios Voulvoulis <contact@nftban.com>" meta:created_date="2026-04-04" meta:description="Dual console+file logger for installer output" meta:inventory.files="internal/installer/logging/logger.go" meta:inventory.binaries="" meta:inventory.env_vars="" meta:inventory.config_files="/var/log/nftban/installer.log" meta:inventory.systemd_units="" meta:inventory.network="" meta:inventory.privileges="root" =============================================================================

Index

Constants

View Source
const DefaultLogPath = "/var/log/nftban/installer.log"

DefaultLogPath is the standard installer log location.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger writes to both console and a persistent log file. The log file is append-only — every install/update/repair run is preserved as a contiguous block delimited by RunHeader/RunFooter for post-mortem analysis.

func New

func New(logPath string, verbose bool) *Logger

New creates a Logger. logPath may be empty to use DefaultLogPath. If the log file cannot be opened, logging continues to console only.

func (*Logger) Close

func (l *Logger) Close()

Close flushes and closes the log file.

func (*Logger) CmdResult

func (l *Logger) CmdResult(name string, exitCode int, stderr string)

CmdResult logs the result of a command execution. This captures every external command's exit code and stderr for root cause analysis. Only writes to file (not console) unless verbose or non-zero exit.

func (*Logger) Debug

func (l *Logger) Debug(format string, args ...interface{})

Debug logs a debug message to file always, and to console only if verbose.

func (*Logger) Detect

func (l *Logger) Detect(category, key, value string)

Detect logs a detection result (SSH, panel, conflicts, authority). These are the key facts needed for root cause analysis.

func (*Logger) Error

func (l *Logger) Error(format string, args ...interface{})

Error logs an error to both console and file.

func (*Logger) ErrorLogOnly added in v1.126.2

func (l *Logger) ErrorLogOnly(format string, args ...interface{})

ErrorLogOnly writes an error to the log file ONLY, NOT to console. Use when the operator-facing console output is handled by a different code path (e.g., V126.2 FAILED_AUTHORITY_ABORT operator-friendly block emitted by main.go report()) but the log file should still preserve the error for audit/diagnosis. This keeps the machine-readable log unchanged while letting the console show a calmer message.

Scope: AUDIT_190_LIFECYCLE/V126_2_INSTALL_ABORT_UX_HOTFIX_SCOPE.md (REV 4)

func (*Logger) FileWriter added in v1.160.0

func (l *Logger) FileWriter() io.Writer

FileWriter returns the open log-file handle as an io.Writer, or nil if no log file could be opened (console-only mode). v1.160 PR-B: the lifecycle bridge uses this to route structured lifecycle JSON to the same persistent installer log instead of the operator console. Returns the *os.File directly; writes to it are appended at the current file offset (the file is opened O_APPEND), so lifecycle JSON interleaves cleanly with the dual-logger's own file lines.

Note: the returned handle is the same one Logger writes to; both write paths are line-oriented appends and the lifecycle logger emits whole-line JSON, so no additional locking is introduced here (the historical Logger file writes were already unsynchronized).

func (*Logger) Info

func (l *Logger) Info(format string, args ...interface{})

Info logs an informational message to both console and file.

func (*Logger) LogPath

func (l *Logger) LogPath() string

LogPath returns the path to the log file being written.

func (*Logger) Phase

func (l *Logger) Phase(name string)

Phase prints a phase separator banner and records the phase start time.

func (*Logger) PhaseEnd

func (l *Logger) PhaseEnd(name string)

PhaseEnd records the elapsed time for the current phase. Called automatically by Phase() for the previous phase, but should also be called for the final phase.

func (*Logger) Result

func (l *Logger) Result(format string, args ...interface{})

Result prints a final result line (no timestamp on console for cleaner output).

func (*Logger) RunFooter

func (l *Logger) RunFooter(finalState string, exitCode int)

RunFooter writes the closing delimiter with elapsed time and final state.

func (*Logger) RunHeader

func (l *Logger) RunHeader(version, mode, hostname, osInfo string)

RunHeader writes a clear delimiter block marking the start of an installer run. This is essential for finding where a specific install/update begins in the log.

func (*Logger) StateChange

func (l *Logger) StateChange(from, to, reason string)

StateChange logs a state machine transition to file.

func (*Logger) Warn

func (l *Logger) Warn(format string, args ...interface{})

Warn logs a warning to both console and file. The warning is also tallied (count + captured message) so the final summary can report it honestly. Warnings remain NON-FATAL — printing/file-writing behavior is unchanged from before v1.160; only the accounting (v1.160 PR-A) is added.

func (*Logger) WarnCount added in v1.160.0

func (l *Logger) WarnCount() int

WarnCount returns the number of non-fatal warnings emitted via Warn() so far. v1.160 PR-A: the final operator summary uses this to decide whether the COMMITTED line should mention warnings.

func (*Logger) Warnings added in v1.160.0

func (l *Logger) Warnings() []string

Warnings returns a copy of the warning messages emitted via Warn() so far. v1.160 PR-A: returns a copy so callers cannot mutate the logger's slice and so the read is consistent under the mutex.

Jump to

Keyboard shortcuts

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