Documentation
¶
Overview ¶
FILE: lixenwraith/log/builder.go
FILE: lixenwraith/log/config.go
FILE: lixenwraith/log/constant.go
FILE: lixenwraith/log/format.go
FILE: lixenwraith/log/heartbeat.go
FILE: lixenwraith/log/logger.go
FILE: lixenwraith/log/processor.go
FILE: lixenwraith/log/record.go
FILE: lixenwraith/log/state.go
FILE: lixenwraith/log/storage.go
FILE: lixenwraith/log/processor.go
FILE: lixenwraith/log/type.go
FILE: lixenwraith/log/utility.go
Index ¶
- Constants
- func Level(levelStr string) (int64, error)
- type Builder
- func (b *Builder) BufferSize(size int64) *Builder
- func (b *Builder) Build() (*Logger, error)
- func (b *Builder) ConsoleTarget(target string) *Builder
- func (b *Builder) Directory(dir string) *Builder
- func (b *Builder) DiskCheckIntervalMs(interval int64) *Builder
- func (b *Builder) EnableAdaptiveInterval(enable bool) *Builder
- func (b *Builder) EnableConsole(enable bool) *Builder
- func (b *Builder) EnableFile(enable bool) *Builder
- func (b *Builder) EnablePeriodicSync(enable bool) *Builder
- func (b *Builder) Extension(ext string) *Builder
- func (b *Builder) FlushIntervalMs(interval int64) *Builder
- func (b *Builder) Format(format string) *Builder
- func (b *Builder) HeartbeatIntervalS(interval int64) *Builder
- func (b *Builder) HeartbeatLevel(level int64) *Builder
- func (b *Builder) InternalErrorsToStderr(enable bool) *Builder
- func (b *Builder) Level(level int64) *Builder
- func (b *Builder) LevelString(level string) *Builder
- func (b *Builder) MaxCheckIntervalMs(interval int64) *Builder
- func (b *Builder) MaxSizeKB(size int64) *Builder
- func (b *Builder) MaxSizeMB(size int64) *Builder
- func (b *Builder) MaxTotalSizeKB(size int64) *Builder
- func (b *Builder) MaxTotalSizeMB(size int64) *Builder
- func (b *Builder) MinCheckIntervalMs(interval int64) *Builder
- func (b *Builder) MinDiskFreeKB(size int64) *Builder
- func (b *Builder) MinDiskFreeMB(size int64) *Builder
- func (b *Builder) Name(name string) *Builder
- func (b *Builder) RetentionCheckMins(mins float64) *Builder
- func (b *Builder) RetentionPeriodHrs(hours float64) *Builder
- func (b *Builder) ShowLevel(show bool) *Builder
- func (b *Builder) ShowTimestamp(show bool) *Builder
- func (b *Builder) TimestampFormat(format string) *Builder
- func (b *Builder) TraceDepth(depth int64) *Builder
- type Config
- type Logger
- func (l *Logger) ApplyConfig(cfg *Config) error
- func (l *Logger) ApplyConfigString(overrides ...string) error
- func (l *Logger) Debug(args ...any)
- func (l *Logger) DebugTrace(depth int, args ...any)
- func (l *Logger) Error(args ...any)
- func (l *Logger) ErrorTrace(depth int, args ...any)
- func (l *Logger) Flush(timeout time.Duration) error
- func (l *Logger) GetConfig() *Config
- func (l *Logger) Info(args ...any)
- func (l *Logger) InfoTrace(depth int, args ...any)
- func (l *Logger) Log(args ...any)
- func (l *Logger) LogStructured(level int64, message string, fields map[string]any)
- func (l *Logger) LogTrace(depth int, args ...any)
- func (l *Logger) Message(args ...any)
- func (l *Logger) Shutdown(timeout ...time.Duration) error
- func (l *Logger) Start() error
- func (l *Logger) Stop(timeout ...time.Duration) error
- func (l *Logger) Warn(args ...any)
- func (l *Logger) WarnTrace(depth int, args ...any)
- func (l *Logger) Write(args ...any)
- type State
- type TimerSet
Constants ¶
const ( LevelDebug int64 = -4 LevelInfo int64 = 0 LevelWarn int64 = 4 LevelError int64 = 8 )
Log level constants
const ( LevelProc int64 = 12 LevelDisk int64 = 16 LevelSys int64 = 20 )
Heartbeat log levels
const ( FlagShowTimestamp int64 = 0b0001 FlagShowLevel int64 = 0b0010 FlagRaw int64 = 0b0100 FlagStructuredJSON int64 = 0b1000 FlagDefault = FlagShowTimestamp | FlagShowLevel )
Record flags for controlling output structure
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder provides a fluent API for building logger configurations It wraps a Config instance and provides chainable methods for setting values
func NewBuilder ¶
func NewBuilder() *Builder
NewBuilder creates a new configuration builder with default values
func (*Builder) BufferSize ¶
BufferSize sets the channel buffer size
func (*Builder) ConsoleTarget ¶
ConsoleTarget sets the console output target ("stdout", "stderr", or "split")
func (*Builder) DiskCheckIntervalMs ¶
DiskCheckIntervalMs sets the disk check interval in milliseconds
func (*Builder) EnableAdaptiveInterval ¶
EnableAdaptiveInterval enables adaptive disk check intervals
func (*Builder) EnableConsole ¶
EnableConsole enables console output
func (*Builder) EnableFile ¶
EnableFile enables file output
func (*Builder) EnablePeriodicSync ¶
EnablePeriodicSync enables periodic file sync
func (*Builder) FlushIntervalMs ¶
FlushIntervalMs sets the flush interval in milliseconds
func (*Builder) HeartbeatIntervalS ¶
HeartbeatIntervalS sets the heartbeat monitoring level
func (*Builder) HeartbeatLevel ¶
HeartbeatLevel sets the heartbeat monitoring level
func (*Builder) InternalErrorsToStderr ¶
InternalErrorsToStderr sets whether to write internal errors to stderr
func (*Builder) LevelString ¶
LevelString sets the log level from a string
func (*Builder) MaxCheckIntervalMs ¶
MaxCheckIntervalMs sets the maximum disk check interval in milliseconds
func (*Builder) MaxTotalSizeKB ¶
MaxTotalSizeKB sets the maximum total size of all log files in KB
func (*Builder) MaxTotalSizeMB ¶
MaxTotalSizeMB sets the maximum total size of all log files in MB
func (*Builder) MinCheckIntervalMs ¶
MinCheckIntervalMs sets the minimum disk check interval in milliseconds
func (*Builder) MinDiskFreeKB ¶
MinDiskFreeKB sets the minimum required free disk space in KB
func (*Builder) MinDiskFreeMB ¶
MinDiskFreeMB sets the minimum required free disk space in MB
func (*Builder) RetentionCheckMins ¶
RetentionCheckMins sets the retention check interval in minutes
func (*Builder) RetentionPeriodHrs ¶
RetentionPeriodHrs sets the log retention period in hours
func (*Builder) ShowTimestamp ¶
ShowTimestamp sets whether to show timestamps in logs
func (*Builder) TimestampFormat ¶
TimestampFormat sets the timestamp format string
func (*Builder) TraceDepth ¶
TraceDepth sets the default trace depth for stack traces
type Config ¶
type Config struct {
// File and Console output settings
EnableConsole bool `toml:"enable_console"` // Enable console output (stdout/stderr)
ConsoleTarget string `toml:"console_target"` // "stdout", "stderr", or "split"
EnableFile bool `toml:"enable_file"` // Enable file output
// Basic settings
Level int64 `toml:"level"` // Log records at or above this Level will be logged
Name string `toml:"name"` // Base name for log files
Directory string `toml:"directory"` // Directory for log files
Format string `toml:"format"` // "txt", "raw", or "json"
Extension string `toml:"extension"` // Log file extension
// Formatting
ShowTimestamp bool `toml:"show_timestamp"` // Add timestamp to log records
ShowLevel bool `toml:"show_level"` // Add level to log record
TimestampFormat string `toml:"timestamp_format"` // Time format for log timestamps
// Buffer and size limits
BufferSize int64 `toml:"buffer_size"` // Channel buffer size
MaxSizeKB int64 `toml:"max_size_kb"` // Max size per log file
MaxTotalSizeKB int64 `toml:"max_total_size_kb"` // Max total size of all logs in dir
MinDiskFreeKB int64 `toml:"min_disk_free_kb"` // Minimum free disk space required
// Timers
FlushIntervalMs int64 `toml:"flush_interval_ms"` // Interval for flushing file buffer
TraceDepth int64 `toml:"trace_depth"` // Default trace depth (0-10)
RetentionPeriodHrs float64 `toml:"retention_period_hrs"` // Hours to keep logs (0=disabled)
RetentionCheckMins float64 `toml:"retention_check_mins"` // How often to check retention
// Disk check settings
DiskCheckIntervalMs int64 `toml:"disk_check_interval_ms"` // Base interval for disk checks
EnableAdaptiveInterval bool `toml:"enable_adaptive_interval"` // Adjust interval based on log rate
EnablePeriodicSync bool `toml:"enable_periodic_sync"` // Periodic sync with disk
MinCheckIntervalMs int64 `toml:"min_check_interval_ms"` // Minimum adaptive interval
MaxCheckIntervalMs int64 `toml:"max_check_interval_ms"` // Maximum adaptive interval
// Heartbeat configuration
HeartbeatLevel int64 `toml:"heartbeat_level"` // 0=disabled, 1=proc only, 2=proc+disk, 3=proc+disk+sys
HeartbeatIntervalS int64 `toml:"heartbeat_interval_s"` // Interval seconds for heartbeat
// Internal error handling
InternalErrorsToStderr bool `toml:"internal_errors_to_stderr"` // Write internal errors to stderr
}
Config holds all logger configuration values
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a copy of the default configuration
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is the core struct that encapsulates all logger functionality
func NewLogger ¶
func NewLogger() *Logger
NewLogger creates a new Logger instance with default settings
func (*Logger) ApplyConfig ¶
ApplyConfig applies a validated configuration to the logger This is the primary way applications should configure the logger
func (*Logger) ApplyConfigString ¶
ApplyConfigString applies string key-value overrides to the logger's current configuration Each override should be in the format "key=value"
func (*Logger) DebugTrace ¶
DebugTrace logs a debug message with function call trace
func (*Logger) ErrorTrace ¶
ErrorTrace logs an error message with function call trace
func (*Logger) Flush ¶
Flush explicitly triggers a sync of the current log file buffer to disk and waits for completion or timeout
func (*Logger) LogStructured ¶
LogStructured logs a message with structured fields as proper JSON
func (*Logger) Shutdown ¶
Shutdown gracefully closes the logger, attempting to flush pending records If no timeout is provided, uses a default of 2x flush interval
func (*Logger) Start ¶
Start begins log processing. Safe to call multiple times Returns error if logger is not initialized
func (*Logger) Stop ¶
Stop halts log processing. Can be restarted with Start() Returns nil if already stopped
type State ¶
type State struct {
// General state
IsInitialized atomic.Bool // Tracks successful initialization, not start of log processor
LoggerDisabled atomic.Bool // Tracks logger stop due to issues (e.g. disk full)
ShutdownCalled atomic.Bool // Tracks if Shutdown() has been called, a terminal state
DiskFullLogged atomic.Bool // Tracks if a disk full error has been logged to prevent log spam
DiskStatusOK atomic.Bool // Tracks if disk space and size limits are currently met
Started atomic.Bool // Tracks calls to Start() and Stop()
ProcessorExited atomic.Bool // Tracks if the processor goroutine is running or has exited
// Outputs
CurrentFile atomic.Value // stores *os.File
StdoutWriter atomic.Value // stores io.Writer (os.Stdout, os.Stderr, or io.Discard)
// File State
CurrentSize atomic.Int64 // Size of the current log file
EarliestFileTime atomic.Value // stores time.Time for retention
// Log state
ActiveLogChannel atomic.Value // stores chan logRecord
DroppedLogs atomic.Uint64 // Counter for logs dropped since last heartbeat
TotalDroppedLogs atomic.Uint64 // Counter for total logs dropped since logger start
// Heartbeat statistics
HeartbeatSequence atomic.Uint64 // Counter for heartbeat sequence numbers
LoggerStartTime atomic.Value // Stores time.Time for uptime calculation
TotalLogsProcessed atomic.Uint64 // Counter for non-heartbeat logs successfully processed
TotalRotations atomic.Uint64 // Counter for successful log rotations
TotalDeletions atomic.Uint64 // Counter for successful log deletions (cleanup/retention)
// contains filtered or unexported fields
}
State encapsulates the runtime state of the logger