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 ¶
- func CleanupOldLogs(logDir string, activeFilePath string, retentionCount int) error
- type Logger
- func (l *Logger) File() *os.File
- func (l *Logger) FilePath() string
- func (l *Logger) LogLevel() slog.Level
- func (l *Logger) LogsDir() string
- func (l *Logger) ReloadFromConfig(logDirectory, logLevel, logRollover string, logRetentionCount int, ...) error
- func (l *Logger) Shutdown() error
- func (l *Logger) SlogLogger() *slog.Logger
- type RetentionTask
- type RolloverTask
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
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) 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 ¶
Shutdown gracefully shuts down the logger by closing the log file. Note: Scheduler shutdown is handled by App.Shutdown(), not here.
func (*Logger) SlogLogger ¶
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.
type RolloverTask ¶
type RolloverTask struct {
// contains filtered or unexported fields
}
RolloverTask implements scheduler.Task for executing log file rollover.