LoggerFile Rotation
File Rotation
The logger supports automatic file rotation based on both date and file size.
Log files are rotated automatically to prevent uncontrolled file growth and to keep log archives organized and manageable in long-running applications.
Rotation
Rotation is controlled through:
MaxFileSize- daily file naming
Example configuration:
package main
import (
"log/slog"
"github.com/netlifeguru/logger"
)
func main() {
closer, err := logger.Init(logger.Config{
Dir: "./logs",
MaxFileSize: 10 * 1024 * 1024, // 10MB
})
if err != nil {
slog.Error(err.Error())
}
defer closer.Close()
slog.Info("logger started")
}Generated files
Example output:
logs/
├── 2026-05-11-0001.log
├── 2026-05-11-0002.log
└── 2026-05-12-0001.logRotation occurs when:
- the current file exceeds the configured size limit
- the current date changes
This provides:
- predictable file sizes
- easier log archival
- simpler debugging by date
- improved compatibility with log collection systems
The default maximum file size is 10MB
File rotation is performed automatically during writes without requiring manual maintenance or application restarts.