logging

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package logging is instigator's leveled log output: ERROR/WARN/INFO/ DEBUG lines with ISO8601 timestamps, built on log/slog. It exists because the flat, single-level log this project started with hid a real bug: an rsh command instcmd refused ("fgrep: not supported") went only to the client's own stderr, never to our side, so serve.log stayed silent about it through a live install failure. A refusal now has a level - ERROR - that's visible in the server's own log by default, not something a client can swallow.

Every existing call site across bootp/tftp/rcmd/instcmd/serve already builds a formatted message with fmt-style verbs; Logger keeps that shape (Debugf/Infof/Warnf/Errorf) rather than moving every call site to slog's structured key-value API, which would be a much bigger change for no benefit here - nothing in this project queries its own logs as structured data.

Index

Constants

View Source
const (
	LevelDebug = slog.LevelDebug // per-packet/per-block decode detail, -v only
	LevelInfo  = slog.LevelInfo  // normal serving: requests answered, transfers made
	LevelWarn  = slog.LevelWarn  // a request refused or malformed on the client's end
	LevelError = slog.LevelError // this side failed to do something it should have
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Level

type Level = slog.Level

Level is a log severity. The four constants below are the only levels instigator uses.

type Logger

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

Logger provides leveled, printf-style logging to one destination. The zero value is not usable; use New. A nil *Logger is safe to call (every method is a no-op), matching the old Logf-unset-means-silent convention every caller and test already relies on.

func New

func New(w io.Writer, min Level) *Logger

New builds a Logger writing one line per record to w: an ISO8601 timestamp (RFC3339 with the local zone offset, e.g. 2026-08-16T16:07:38-07:00), the level, then the formatted message. min is the lowest level actually written; records below it cost nothing beyond a level comparison, since Debugf/Infof/etc. check it before formatting their arguments.

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...any)

func (*Logger) Enabled

func (l *Logger) Enabled(level Level) bool

Enabled reports whether a message at level would actually be written. A hot path that builds expensive-to-format arguments (a per-packet decode, say) should check this before doing that work, rather than relying on Debugf to discard the message afterward.

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...any)

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...any)

func (*Logger) Warnf

func (l *Logger) Warnf(format string, args ...any)

Jump to

Keyboard shortcuts

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