mirror of
https://github.com/foomo/contentserver.git
synced 2025-10-16 12:25:44 +00:00
logging: set console encoding explicitely if LOG_JSON env var is not set
This commit is contained in:
parent
f5d1117c67
commit
a2b0eabb41
@ -17,22 +17,26 @@ var (
|
||||
// SetupLogging configures the logger
|
||||
func SetupLogging(debug bool, outputPath string) {
|
||||
|
||||
var err error
|
||||
var (
|
||||
zc zap.Config
|
||||
err error
|
||||
)
|
||||
|
||||
if debug {
|
||||
zc := zap.NewDevelopmentConfig()
|
||||
if os.Getenv("LOG_JSON") == "1" {
|
||||
zc.Encoding = "json"
|
||||
}
|
||||
zc = zap.NewDevelopmentConfig()
|
||||
zc.OutputPaths = append(zc.OutputPaths, outputPath)
|
||||
Log, err = zc.Build()
|
||||
} else {
|
||||
zc := zap.NewProductionConfig()
|
||||
if os.Getenv("LOG_JSON") == "1" {
|
||||
zc.Encoding = "json"
|
||||
}
|
||||
zc = zap.NewProductionConfig()
|
||||
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 {
|
||||
log.Fatalf("can't initialize zap logger: %v", err)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user