Documentation
¶
Index ¶
- Variables
- func BackendCaller() (string, string, int, bool)
- type Backend
- type BackendConfig
- type BackendEntry
- type CallerInfo
- type CommonBackend
- type Entry
- type Loggee
- func (l *Loggee) AddBackend(backend Backend)
- func (l *Loggee) AddBackendWithConfig(backend Backend, cfg BackendConfig)
- func (l *Loggee) Log(entry *Entry) error
- func (l *Loggee) LogWithOffset(offset int, 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
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 ( // TRACE captures extremely fine-grained diagnostic events. TRACE = Severity{Representation: "TRACE", Index: 0, Fatal: false} // DEBUG captures verbose diagnostic events above TRACE. DEBUG = Severity{Representation: "DEBUG", 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} )
Built-in severities ordered by severity index.
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).
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 BackendEntry ¶ added in v0.12.0
type BackendEntry struct {
Backend Backend
// Config overrides the logger-level backend config. When nil, the logger's
// configuration is used.
Config *BackendConfig
}
BackendEntry allows specifying backend-specific configuration when building loggers.
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 {
// 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 import path package when caller
// tracking is enabled (for example: example.com/project/subsystem).
// Loggee computes this field from the call stack and ignores caller input.
Package string
// File contains the base filename of the call site.
// Loggee computes this field from the call stack and ignores caller input.
File string
// Line contains the source line number of the call site.
// Loggee computes this field from the call stack and ignores caller input.
Line int
// Meta holds arbitrary key/value pairs to attach to the entry payload.
Meta map[string]any
// contains filtered or unexported fields
}
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) AddBackendWithConfig ¶ added in v0.12.0
func (l *Loggee) AddBackendWithConfig(backend Backend, cfg BackendConfig)
AddBackendWithConfig registers a backend using a specific configuration.
func (*Loggee) Log ¶
Log writes the entry to every backend and panics if the severity is fatal. It is shorthand for LogWithOffset(1, entry) so caller metadata skips this wrapper frame.
func (*Loggee) LogWithOffset ¶ added in v0.12.11
LogWithOffset writes the entry to every backend and panics if the severity is fatal. offset adds extra caller stack frames on top of LoggerConfig's CallerSkip so wrapper functions can preserve accurate caller metadata. Caller metadata fields on entry (Package/File/Line) are ignored.
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.
// Wrapper layers should call LogWithOffset to add their own frame depth
// and keep package/file/line metadata accurate.
CallerSkip int
// Backend controls the optional fields each backend should emit.
Backend BackendConfig
// Gate sets the minimum severity index accepted by the logger (applied to
// all attached backends). Defaults to zero (no filtering).
Gate uint
}
LoggerConfig describes how a single logger instance should behave.
type LoggerDefinition ¶ added in v0.11.0
type LoggerDefinition struct {
Config LoggerConfig
// Backends is kept for backward compatibility and applies the logger-level
// backend configuration to every backend listed here.
Backends []Backend
// BackendEntries allow specifying backend-specific configurations.
BackendEntries []BackendEntry
}
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.
func ParseSeverity ¶ added in v0.12.0
ParseSeverity returns the matching built-in severity by name (case insensitive). This helper primarily serves internal integrations (e.g. scripting); most library users should reference the predefined severities directly.
Source Files
¶
- Backend.go
- Callers.go
- Config.go
- Entry.go
- Loggee.go
- Severity.go