logger

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: LGPL-2.1 Imports: 22 Imported by: 0

README

mod/logger

mod/logger builds the process logger from configuration. It wires console output, rotating file output, and optional VictoriaLogs shipping into one logger used by runtime packages.

Place in the Runtime

flowchart LR
  config["stconf config"] --> logger["mod/logger"]
  logger --> console["console sink"]
  logger --> file["rotating file sink"]
  logger --> remote["VictoriaLogs sink"]
  runtime["runtime packages"] --> logger

Responsibilities

  • Build a structured logger from logging.* config.
  • Normalize sink levels and disabled sinks.
  • Configure log file rotation limits.
  • Keep user-facing log messages in English.
  • Provide a no-surprise logger for startup, runtime, and maintenance commands.

Contracts

  • Logger construction should not start the main runtime.
  • A disabled sink must not allocate background workers.
  • Remote logging failures must not crash the mirror. They are operational degradation, not data corruption.
  • Logs should use stable, low-cardinality fields such as component, key, version, and request id.

Important Files

  • obj.go: logger construction and sink selection.
  • level.go: level parsing.
  • writer.go: sink adapters.

Operational Notes

Use file logging for persistent node diagnostics. Console logging is usually enough for containers. VictoriaLogs is optional and should be treated as best-effort telemetry.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Obj

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

Obj is the assembled logger: zerolog value, closeable sinks, and optional VictoriaLogs sink reference.

func New

func New(configObj *stcfg.ConfigObj) (*Obj, error)

New builds a multiplexed zerolog from enabled sinks; the effective level is the minimum sink level. It fails when no sink is enabled.

func (*Obj) Close

func (obj *Obj) Close() error

Close closes all sinks exactly once and is safe on a nil receiver.

func (*Obj) RegisterMetrics

func (obj *Obj) RegisterMetrics(meterObj metric.Meter) error

RegisterMetrics publishes VictoriaLogs delivery self-metrics in the internal group: dropped records and push failures. Without a VictoriaLogs sink or meter it is a no-op, and it depends only on neutral otel/metric.

func (*Obj) XErr

func (obj *Obj) XErr(err error) *zerolog.Event

XErr expands stcode errors into structured events with their fields; other errors use Error.Err.

func (*Obj) Zero

func (obj *Obj) Zero() *zerolog.Logger

Zero returns the underlying zerolog.Logger for structured logging.

Jump to

Keyboard shortcuts

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