Proper log rotation, filename compatibility with windows

This commit is contained in:
Ben Adrian Sarmiento
2024-07-06 12:44:25 +02:00
parent b501b800dd
commit 467f51bdec
6 changed files with 67 additions and 15 deletions

View File

@@ -54,11 +54,13 @@ func NewLogger(logPath string) *Logger {
consoleEncoderCore := zapcore.NewCore(consoleEncoder, zapcore.AddSync(os.Stdout), zapLevel)
// Set up file logging with overwrite mode
logFile := zapcore.AddSync(&lumberjack.Logger{
lj := lumberjack.Logger{
Filename: logPath,
MaxSize: 10, // megabytes
MaxBackups: 20,
})
}
lj.Rotate()
logFile := zapcore.AddSync(&lj)
fmt.Println("Logging to", logPath)
fileCfg := zapcore.EncoderConfig{