core: Support NO_COLOR env var to disable log coloring (#6078)

This commit is contained in:
Aziz Rmadi 2024-02-01 20:12:42 -06:00 committed by GitHub
parent 223f314331
commit a7479302fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -717,7 +717,10 @@ func newDefaultProductionLogEncoder(wo WriterOpener) zapcore.Encoder {
encCfg.EncodeTime = func(ts time.Time, encoder zapcore.PrimitiveArrayEncoder) {
encoder.AppendString(ts.UTC().Format("2006/01/02 15:04:05.000"))
}
encCfg.EncodeLevel = zapcore.CapitalColorLevelEncoder
if coloringEnabled {
encCfg.EncodeLevel = zapcore.CapitalColorLevelEncoder
}
return zapcore.NewConsoleEncoder(encCfg)
}
return zapcore.NewJSONEncoder(encCfg)
@ -758,6 +761,7 @@ func Log() *zap.Logger {
}
var (
coloringEnabled = os.Getenv("NO_COLOR") == "" && os.Getenv("TERM") != "xterm-mono"
defaultLogger, _ = newDefaultProductionLog()
defaultLoggerMu sync.RWMutex
)