logger

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package logger provides the process-wide zerolog singleton.

File output uses core/logger/rotate.Writer (date + size rotation, direct O_APPEND writes, no userspace buffer). Msglog shares the same writer type via msgbus.MsgLogger.

Logging discipline (P2-3)

The plaintext msglog (core/msgbus.MsgLogger, JSONL) is the SOLE per-event record. Zerolog text logging exists for lifecycle transitions (startup, connect, disconnect, shutdown) and cold error paths only. The rules:

  1. No log statement above Debug on hot paths: the dispatch loop, ring-buffer and arena operations (core/mem, core/msgbus Allocate/Publish/Dispatch/Send), and per-message adapter parse paths (dataclient processMessage and everything it calls).
  2. High-frequency conditions — event drops, overflow waits, unrouted commands — are recorded as atomic counters at the point of occurrence and surfaced by a low-frequency observer goroutine (msgbus.StartObserver, 1 s cadence), never logged inline.
  3. Fatal/Panic are permitted anywhere: they terminate the process, so they cannot recur at event rate.
  4. Debug is permitted on hot paths for diagnostics, because zerolog short-circuits disabled levels without allocating; production runs at Info or above. Do not compute log arguments outside the zerolog call chain (no fmt.Sprintf, no Interface() of live structs).

These rules are enforced statically by internal/lint (TestHotPathLogging), which rejects Info/Warn/Error calls in the designated hot-path functions and any logger import in core/mem.

Index

Constants

This section is empty.

Variables

View Source
var Log = consoleLogger

Log is kept for backward compatibility; defaults to console logger. Deprecated: Use Get() for the singleton logger.

Functions

func Close

func Close() error

Close closes the underlying file writer, if any.

func Get

func Get() zerolog.Logger

Get returns the global singleton logger instance.

func Init

func Init(opts Options) error

Init initializes the global singleton logger with the provided options.

func Sync

func Sync() error

Sync fsyncs the file writer when SyncPeriodic (or any explicit sync) is desired.

Types

type Config

type Config struct {
	Level  string            `yaml:"level"`
	Stdout *bool             `yaml:"stdout"` // nil defaults to true
	File   rotate.FileConfig `yaml:"file"`   // empty Dir = no file output
}

Config contains logger configuration.

func (Config) ToOptions

func (c Config) ToOptions() Options

ToOptions converts a Config to an Options struct for Init().

type Options

type Options struct {
	Level  string            // Log level: trace, debug, info, warn, error, fatal, panic
	Stdout bool              // Write human-readable logs to stdout (default true via Config)
	File   rotate.FileConfig // File output; empty Dir disables file logging
}

Options contains configuration options for the logger.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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