Documentation
¶
Index ¶
- Variables
- func BackendCaller() (string, string, int, bool)
- func ZeroLog(severity *Severity, message string, fields map[string]any)
- func ZeroLogSetup(writers ...io.Writer)
- type Backend
- type BackendConfig
- type CallerInfo
- type CommonBackend
- type Entry
- type Loggee
- func (l *Loggee) AddBackend(backend Backend)
- func (l *Loggee) Log(entry *Entry) error
- func (l *Loggee) NotifyAboutDefaults()
- func (l *Loggee) NotifyAboutSenders(senders ...string)
- func (l *Loggee) NotifyAboutSeverities(severities ...*Severity)
- func (l *Loggee) SetGate(gate uint)
- func (l *Loggee) Shutdown()
- type LoggerConfig
- type LoggerDefinition
- type LoggingSystemConfig
- type Severity
- type ZeroLogWriter
Constants ¶
This section is empty.
Variables ¶
var ( // ErrLoggerNameEmpty indicates a logger definition without a name. ErrLoggerNameEmpty = errors.New("log: logger name cannot be empty") // ErrLoggerNameDuplicate indicates more than one logger used the same name. ErrLoggerNameDuplicate = errors.New("log: duplicate logger name") )
var ( // DEBUG captures verbose diagnostic events. DEBUG = Severity{ Representation: "DEBUG", Index: 0, Fatal: false, } // TRACE represents extremely fine-grained events slightly above DEBUG. TRACE = Severity{ Representation: "TRACE", Index: 10, Fatal: false, } // INFO is for high-level informational events. INFO = Severity{ Representation: "INFO", Index: 20, Fatal: false, } // WARNING indicates a recoverable problem worth operator attention. WARNING = Severity{ Representation: "WARNING", Index: 30, Fatal: false, } // ERROR marks failures that typically require action. ERROR = Severity{ Representation: "ERROR", Index: 40, Fatal: false, } // CRITICAL signals system breaking events and is marked fatal. CRITICAL = Severity{ Representation: "CRITICAL", Index: 50, Fatal: true, } )
ErrLoggerClosed is returned when submitting to a logger that was shut down.
Functions ¶
func BackendCaller ¶ added in v0.11.0
BackendCaller returns the package, source file (base name) and line number of the calling site that invoked logging, from the perspective of a backend.
It attempts several skip depths to account for different call paths (direct backend usage in tests vs. going through Loggee.Log).
func ZeroLog ¶ added in v0.11.0
ZeroLog logs a message with the provided severity and additional fields using zerolog. The caller's package, source file and line number are added to the JSON payload.
Types ¶
type Backend ¶
type Backend interface {
// Write emits the entry and returns any backend specific error.
Write(entry *Entry) error
// NotifyAboutSender allows a backend to adjust formatting/alignment.
NotifyAboutSender(sender string)
// NotifyAboutSeverity allows the backend to precalculate severity spacing.
NotifyAboutSeverity(severity *Severity)
// Shutdown releases backend resources.
Shutdown()
// SetGate configures the minimum severity accepted by the backend.
SetGate(gate uint)
// Configure applies backend-wide feature flags.
Configure(cfg BackendConfig)
}
Backend defines the interface implemented by logging backends such as zerolog, stdlog, or sqlite writers.
type BackendConfig ¶ added in v0.11.0
type BackendConfig struct {
IncludeTimestamp bool
IncludePackage bool
IncludeFile bool
IncludeLine bool
}
BackendConfig controls which optional fields a backend should emit. All backends must respect these flags to remain interchangeable.
func DefaultBackendConfig ¶ added in v0.11.0
func DefaultBackendConfig() BackendConfig
DefaultBackendConfig enables the full feature set supported by every backend.
type CallerInfo ¶ added in v0.11.0
CallerInfo captures metadata about the source location of a log event.
type CommonBackend ¶
type CommonBackend struct {
// Gate is the minimum severity index the backend will emit.
Gate uint
// Config stores the currently applied backend configuration.
Config BackendConfig
// contains filtered or unexported fields
}
CommonBackend provides shared helpers such as gate tracking and config.
func (*CommonBackend) Configure ¶ added in v0.11.0
func (back *CommonBackend) Configure(cfg BackendConfig)
Configure stores the backend configuration.
func (*CommonBackend) EnsureConfig ¶ added in v0.11.0
func (back *CommonBackend) EnsureConfig()
EnsureConfig lazily initializes the configuration to defaults.
func (*CommonBackend) SetGate ¶
func (back *CommonBackend) SetGate(gate uint)
SetGate implements Backend.SetGate for embedders.
type Entry ¶
type Entry struct {
// Time captures when the event occurred. Backends may fill it in when zero.
Time time.Time
// Severity references the severity metadata for the event.
Severity *Severity
// Message is the human readable text payload.
Message string
// Sender identifies the logical component or subsystem.
Sender string
// Package contains the originating Go package when caller tracking is enabled.
Package string
// File contains the base filename of the call site.
File string
// Line contains the source line number of the call site.
Line int
// CustomData contains backend specific key-value pairs to include.
CustomData map[string]any
}
Entry represents a single log line regardless of backend implementation.
type Loggee ¶
type Loggee struct {
// contains filtered or unexported fields
}
Loggee coordinates multiple backends and relays log entries to each of them. It serializes all writes through a channel to remain concurrency-safe without relying on mutex locking.
func NewLoggee ¶ added in v0.11.0
func NewLoggee(cfg LoggerConfig, backends ...Backend) *Loggee
NewLoggee creates a configured logger that immediately starts its background processing goroutine. Additional backends can still be attached via AddBackend after construction.
func (*Loggee) AddBackend ¶
AddBackend registers a backend for future log entries.
func (*Loggee) Log ¶
Log writes the entry to every backend and panics if the severity is fatal.
func (*Loggee) NotifyAboutDefaults ¶
func (l *Loggee) NotifyAboutDefaults()
NotifyAboutDefaults pre-registers the default severities with each backend.
func (*Loggee) NotifyAboutSenders ¶
NotifyAboutSenders informs backends about known senders so they can prepare alignment or metadata caches.
func (*Loggee) NotifyAboutSeverities ¶
NotifyAboutSeverities informs backends about available severity metadata.
func (*Loggee) SetGate ¶
SetGate updates the severity gate across all backends.
type LoggerConfig ¶ added in v0.11.0
type LoggerConfig struct {
// Name identifies the logger when building multiple instances.
Name string
// QueueSize controls the channel buffer length used to serialize writes.
// When zero, a reasonable default buffer of 64 entries is used.
QueueSize int
// CallerSkip controls how many stack frames to skip before resolving
// caller information. Zero uses the default internal offset.
CallerSkip int
// Backend controls the optional fields each backend should emit.
Backend BackendConfig
}
LoggerConfig describes how a single logger instance should behave.
type LoggerDefinition ¶ added in v0.11.0
type LoggerDefinition struct {
Config LoggerConfig
Backends []Backend
}
LoggerDefinition couples a logger configuration with the backends it should drive.
type LoggingSystemConfig ¶ added in v0.11.0
type LoggingSystemConfig struct {
Loggers []LoggerDefinition
}
LoggingSystemConfig enumerates all loggers a process should initialize.
func (LoggingSystemConfig) Build ¶ added in v0.11.0
func (cfg LoggingSystemConfig) Build() (map[string]*Loggee, error)
Build instantiates every logger defined in the configuration and returns them keyed by name. Logger names must be unique and non-empty.
type Severity ¶
type Severity struct {
// Representation is the printable textual label (e.g. "INFO").
Representation string
// Index orders severities for comparisons and gating.
Index uint
// Fatal indicates that logging at this level should panic after writing.
Fatal bool
}
Severity describes a log level with a symbolic name, index and fatal flag.
type ZeroLogWriter ¶ added in v0.11.0
type ZeroLogWriter struct {
// contains filtered or unexported fields
}
ZeroLogWriter maps severities to receivers and holds a gate. Gate semantics: only log events with severity.Index >= gate.
Source Files
¶
- Backend.go
- Callers.go
- Config.go
- Defaults.go
- Entry.go
- Loggee.go
- Severity.go
- ZeroLog.go