feat: log to console in dev

This commit is contained in:
Simon Ding
2024-07-28 11:08:17 +08:00
parent ef9e4487c6
commit 3a4e303d9d
2 changed files with 12 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
package log
import (
"os"
"path/filepath"
"strings"
@@ -18,12 +19,16 @@ func init() {
atom = zap.NewAtomicLevel()
atom.SetLevel(zap.DebugLevel)
w := zapcore.AddSync(&lumberjack.Logger{
Filename: filepath.Join(dataPath, "logs", "polaris.log"),
MaxSize: 50, // megabytes
MaxBackups: 3,
MaxAge: 30, // days
})
w := zapcore.Lock(os.Stdout)
if os.Getenv("GIN_MODE") == "release" {
w = zapcore.AddSync(&lumberjack.Logger{
Filename: filepath.Join(dataPath, "logs", "polaris.log"),
MaxSize: 50, // megabytes
MaxBackups: 3,
MaxAge: 30, // days
})
}
consoleEncoder := zapcore.NewConsoleEncoder(zap.NewDevelopmentEncoderConfig())