mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-27 06:03:48 +03:00
core: Support NO_COLOR env var to disable log coloring (#6078)
This commit is contained in:
parent
223f314331
commit
a7479302fc
1 changed files with 5 additions and 1 deletions
|
@ -717,7 +717,10 @@ func newDefaultProductionLogEncoder(wo WriterOpener) zapcore.Encoder {
|
||||||
encCfg.EncodeTime = func(ts time.Time, encoder zapcore.PrimitiveArrayEncoder) {
|
encCfg.EncodeTime = func(ts time.Time, encoder zapcore.PrimitiveArrayEncoder) {
|
||||||
encoder.AppendString(ts.UTC().Format("2006/01/02 15:04:05.000"))
|
encoder.AppendString(ts.UTC().Format("2006/01/02 15:04:05.000"))
|
||||||
}
|
}
|
||||||
|
if coloringEnabled {
|
||||||
encCfg.EncodeLevel = zapcore.CapitalColorLevelEncoder
|
encCfg.EncodeLevel = zapcore.CapitalColorLevelEncoder
|
||||||
|
}
|
||||||
|
|
||||||
return zapcore.NewConsoleEncoder(encCfg)
|
return zapcore.NewConsoleEncoder(encCfg)
|
||||||
}
|
}
|
||||||
return zapcore.NewJSONEncoder(encCfg)
|
return zapcore.NewJSONEncoder(encCfg)
|
||||||
|
@ -758,6 +761,7 @@ func Log() *zap.Logger {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
coloringEnabled = os.Getenv("NO_COLOR") == "" && os.Getenv("TERM") != "xterm-mono"
|
||||||
defaultLogger, _ = newDefaultProductionLog()
|
defaultLogger, _ = newDefaultProductionLog()
|
||||||
defaultLoggerMu sync.RWMutex
|
defaultLoggerMu sync.RWMutex
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue