fix: improve logger initialization and reduce cache TTL

This commit is contained in:
krau
2025-05-08 21:03:48 +08:00
parent 70e83e62d9
commit 66454b082a
2 changed files with 12 additions and 13 deletions

View File

@@ -25,15 +25,16 @@ func InitLogger() {
}
}
consoleH := handler.NewConsoleHandler(logLevels)
fileH, err := handler.NewTimeRotateFile(
logFilePath,
rotatefile.EveryDay,
handler.WithLogLevels(slog.AllLevels),
handler.WithBackupNum(logBackupNum),
handler.WithBuffSize(0),
)
if err != nil {
panic(err)
Log.AddHandler(consoleH)
if logFilePath != "" && logBackupNum > 0 {
fileH, err := handler.NewTimeRotateFile(
logFilePath,
rotatefile.EveryDay,
handler.WithLogLevels(slog.AllLevels),
handler.WithBackupNum(logBackupNum))
if err != nil {
panic(err)
}
Log.AddHandler(fileH)
}
Log.AddHandlers(consoleH, fileH)
}