use logrus.JSONFormatter instead of logrus.TextFormatter when mode == production

This commit is contained in:
Dawid Wysokiński 2021-04-22 18:24:40 +02:00
parent 78531f8a13
commit 1fc884b151
1 changed files with 11 additions and 4 deletions

15
main.go
View File

@ -168,10 +168,17 @@ func setupLogger() {
logrus.SetLevel(logrus.DebugLevel)
}
customFormatter := new(logrus.TextFormatter)
customFormatter.TimestampFormat = "2006-01-02 15:04:05"
customFormatter.FullTimestamp = true
logrus.SetFormatter(customFormatter)
timestampFormat := "2006-01-02 15:04:05"
if mode.Get() == mode.ProductionMode {
customFormatter := new(logrus.JSONFormatter)
customFormatter.TimestampFormat = timestampFormat
logrus.SetFormatter(customFormatter)
} else {
customFormatter := new(logrus.TextFormatter)
customFormatter.TimestampFormat = timestampFormat
customFormatter.FullTimestamp = true
logrus.SetFormatter(customFormatter)
}
}
func setupRouter() *gin.Engine {