log

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(level, format string) *slog.Logger

New builds a slog.Logger whose handler writes to os.Stderr via a SwappableWriter. The default constructor is preserved for callers that don't need the swap surface.

Types

type MessageLog added in v0.1.9

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

MessageLog writes a human-readable, per-event decoded-message log — the GopherTrunk analogue of SDRtrunk's per-channel decoded message log. It subscribes to the events bus and appends one timestamped line per trunking event (grants, control-channel lock/loss, affiliations, registrations, patches, talker aliases, locations, tone alerts, decode errors). The file rotates to "<path>.1" when it exceeds the configured size cap.

func NewMessageLog added in v0.1.9

func NewMessageLog(opts MessageLogOptions) (*MessageLog, error)

NewMessageLog opens the log file and subscribes to the bus.

func (*MessageLog) Close added in v0.1.9

func (m *MessageLog) Close() error

Close releases the bus subscription, waits for Run to drain, and closes the file.

func (*MessageLog) Run added in v0.1.9

func (m *MessageLog) Run(ctx context.Context) error

Run drains events until ctx cancels or the bus closes.

type MessageLogOptions added in v0.1.9

type MessageLogOptions struct {
	Bus *events.Bus
	// Path is the log file path. Required.
	Path string
	// MaxSizeMB caps the file size before rotation. Default 16.
	MaxSizeMB int
}

MessageLogOptions configure a MessageLog.

type SwappableWriter added in v0.1.5

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

SwappableWriter is an io.Writer that can be redirected to a different target at runtime without re-wiring the slog handler. The daemon installs one as the slog sink at startup; the launcher redirects it to a tempfile while the in-process TUI owns the terminal, then restores it on exit so headless mode keeps stderr.

func NewSwappableWriter added in v0.1.5

func NewSwappableWriter(w io.Writer) *SwappableWriter

NewSwappableWriter returns a SwappableWriter pointed at w.

func NewWithSwap added in v0.1.5

func NewWithSwap(level, format string) (*slog.Logger, *SwappableWriter)

NewWithSwap is the variant used by main: it returns both the slog Logger and the SwappableWriter behind its handler, so the launcher can redirect stderr while the TUI runs.

func (*SwappableWriter) Redirect added in v0.1.5

func (s *SwappableWriter) Redirect(w io.Writer)

Redirect replaces the active target. The previous target is remembered so Restore can reinstate it.

func (*SwappableWriter) Restore added in v0.1.5

func (s *SwappableWriter) Restore()

Restore reverts to the writer that was active before the most recent Redirect. No-op when nothing was saved.

func (*SwappableWriter) Write added in v0.1.5

func (s *SwappableWriter) Write(p []byte) (int, error)

Write delegates to the active target. Holds the mutex briefly so concurrent log lines never interleave with a redirect transition.

Jump to

Keyboard shortcuts

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