From 938421fcc84a78a78c36b7e93e506473ab12225e Mon Sep 17 00:00:00 2001 From: Mmx Date: Tue, 15 Oct 2024 15:23:33 +0800 Subject: [PATCH] fix: log init panic reference to #41 --- internal/config/log.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/internal/config/log.go b/internal/config/log.go index 3653017..752d9e1 100644 --- a/internal/config/log.go +++ b/internal/config/log.go @@ -13,14 +13,16 @@ import ( var Logger *log.Logger +func newLogFormater(noColors bool) log.Formatter { + return &nested.Formatter{ + NoColors: noColors, + TimestampFormat: "2006-01-02 15:04:05", + } +} + func initLogPre() { Logger = log.New() - - //设置输出格式 - Logger.SetFormatter(&nested.Formatter{ - NoColors: Settings.Log.WriteFile, - TimestampFormat: "2006-01-02 15:04:05", - }) + Logger.SetFormatter(newLogFormater(false)) } func initLogFinal() { @@ -49,7 +51,10 @@ func initLogFinal() { logger.Fatalln(err) } - //设置双重输出 + // Disable log colors + Logger.SetFormatter(newLogFormater(true)) + + // set multiple log output mw := io.MultiWriter(os.Stdout, f) Logger.SetOutput(mw) }