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