Skip to content

Commit

Permalink
fix: log init panic
Browse files Browse the repository at this point in the history
reference to #41
  • Loading branch information
Mmx233 committed Oct 15, 2024
1 parent 7662d94 commit 938421f
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions internal/config/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 938421f

Please sign in to comment.