Documentation
¶
Overview ¶
Package workerlog provides file-based logging for background workers with automatic rotation.
The Writer writes log entries to date-stamped files and automatically removes old files when the maximum number of files is exceeded.
Basic usage:
writer := workerlog.NewWriter("var/logs/workers", 7)
err := writer.Write("my-worker", []string{"Task started", "Task completed"})
Features:
- Date-based file naming: worker-YYYY-MM-DD.log
- Automatic file rotation (oldest files deleted when limit exceeded)
- Thread-safe operations
- Simple API for reading log files
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer writes worker logs to files with automatic rotation.
func NewWriter ¶
NewWriter creates a new Writer.
- baseDir: directory for log storage (e.g., "var/logs/workers")
- maxFiles: maximum number of files per worker (oldest are deleted)
func (*Writer) GetLogFiles ¶
GetLogFiles returns a list of log files for a worker (most recent files first). Returns files sorted by date (newest first), limited to the specified count.
func (*Writer) ReadLogFile ¶
ReadLogFile reads the content of a worker's log file by date
Click to show internal directories.
Click to hide internal directories.