change empty filepath to executable name

This commit is contained in:
Adrian Zürcher
2025-12-12 10:01:11 +01:00
parent a022a9a8ba
commit 62238574cb

View File

@@ -3,6 +3,8 @@ package logging
import (
"fmt"
"os"
"path/filepath"
"strings"
"time"
"go.uber.org/zap"
@@ -32,7 +34,8 @@ func NewLogger(file string, cfg *Config) (*Logger, error) {
}
if file == "" {
file = "NewLogger.log"
file = os.Args[0]
file = strings.Replace(filepath.Base(file), filepath.Ext(file), ".log", 1)
}
encoderConfig := zap.NewProductionEncoderConfig()
@@ -44,9 +47,9 @@ func NewLogger(file string, cfg *Config) (*Logger, error) {
fileSyncer := zapcore.AddSync(&lumberjack.Logger{
Filename: file,
MaxSize: 1, // megabytes
MaxBackups: 3,
MaxAge: 28, // days
MaxSize: cfg.MaxSize, // megabytes
MaxBackups: cfg.MaxBackup,
MaxAge: cfg.MaxAge, // days
})
// Create core list