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
|
// 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)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user