log

package
v0.1.149 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package log provides structured logging functionality with file and console output. It supports bootstrap logging during initialization, configuration-based reloading, log file rollover (daily, weekly, monthly), and log retention management. All logging operations are thread-safe.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupOldLogs

func CleanupOldLogs(logDir string, activeFilePath string, retentionCount int) error

CleanupOldLogs removes log files exceeding the retention count. It never deletes the active log file.

Types

type Logger

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

Logger encapsulates all logging state and functionality. It manages log file creation, handler setup, and scheduler task management. All operations are thread-safe.

func NewBootstrapLogger

func NewBootstrapLogger(rootDir string, sched *scheduler.Scheduler, version string) (*Logger, error)

NewBootstrapLogger creates a new logger for the bootstrap phase. It creates the logs directory and log file, but does NOT schedule rollover tasks. Rollover is only scheduled after config is loaded in ReloadFromConfig().

func (*Logger) File

func (l *Logger) File() *os.File

File returns the current log file handle. The returned file should not be closed by the caller as it is managed by Logger.

func (*Logger) FilePath

func (l *Logger) FilePath() string

FilePath returns the absolute path to the current log file.

func (*Logger) LogLevel

func (l *Logger) LogLevel() slog.Level

LogLevel returns the current log level.

func (*Logger) LogsDir

func (l *Logger) LogsDir() string

LogsDir returns the absolute path to the current logs directory.

func (*Logger) ReloadFromConfig

func (l *Logger) ReloadFromConfig(logDirectory, logLevel, logRollover string, logRetentionCount int, sched *scheduler.Scheduler) error

ReloadFromConfig reinitializes logging based on the provided config values. If the configured LogDirectory matches the bootstrap directory, it only updates the log level if needed. If the configured LogDirectory differs, it closes the old log file and opens a new one in the configured directory with the same filename (for alignment purposes). It also schedules rollover and retention tasks if not already scheduled. Returns error if the new directory cannot be created, the file cannot be opened, or the log level is invalid. sched may be nil if scheduler is not yet initialized - in that case, tasks are not scheduled.

func (*Logger) Shutdown

func (l *Logger) Shutdown() error

Shutdown gracefully shuts down the logger by closing the log file. Note: Scheduler shutdown is handled by App.Shutdown(), not here.

func (*Logger) SlogLogger

func (l *Logger) SlogLogger() *slog.Logger

SlogLogger returns the underlying slog.Logger instance. This can be used to access the structured logger directly if needed.

type RetentionTask

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

RetentionTask implements scheduler.Task for executing retention cleanup.

func (*RetentionTask) Run

func (t *RetentionTask) Run(ctx context.Context) error

Run executes the retention cleanup.

type RolloverTask

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

RolloverTask implements scheduler.Task for executing log file rollover.

func (*RolloverTask) Run

func (t *RolloverTask) Run(ctx context.Context) error

Run executes the rollover: closes current log file, creates new file, updates logger state, and triggers retention cleanup.

Jump to

Keyboard shortcuts

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