logging: set console encoding explicitely if LOG_JSON env var is not set

This commit is contained in:
Philipp Mieden 2019-05-29 15:17:47 +02:00
parent f5d1117c67
commit a2b0eabb41

View File

@ -17,22 +17,26 @@ var (
// SetupLogging configures the logger // SetupLogging configures the logger
func SetupLogging(debug bool, outputPath string) { func SetupLogging(debug bool, outputPath string) {
var err error var (
zc zap.Config
err error
)
if debug { if debug {
zc := zap.NewDevelopmentConfig() zc = zap.NewDevelopmentConfig()
if os.Getenv("LOG_JSON") == "1" {
zc.Encoding = "json"
}
zc.OutputPaths = append(zc.OutputPaths, outputPath) zc.OutputPaths = append(zc.OutputPaths, outputPath)
Log, err = zc.Build()
} else { } else {
zc := zap.NewProductionConfig() zc = zap.NewProductionConfig()
if os.Getenv("LOG_JSON") == "1" {
zc.Encoding = "json"
}
zc.OutputPaths = append(zc.OutputPaths, outputPath) zc.OutputPaths = append(zc.OutputPaths, outputPath)
Log, err = zc.Build()
} }
if os.Getenv("LOG_JSON") == "1" {
zc.Encoding = "json"
} else {
zc.Encoding = "console"
}
Log, err = zc.Build()
if err != nil { if err != nil {
log.Fatalf("can't initialize zap logger: %v", err) log.Fatalf("can't initialize zap logger: %v", err)
} }