Skip to content

Commit

Permalink
core: Support NO_COLOR env var to disable log coloring (#6078)
Browse files Browse the repository at this point in the history
  • Loading branch information
armadi1809 committed Feb 2, 2024
1 parent 223f314 commit a747930
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -758,6 +761,7 @@ func Log() *zap.Logger {
}

var (
coloringEnabled = os.Getenv("NO_COLOR") == "" && os.Getenv("TERM") != "xterm-mono"
defaultLogger, _ = newDefaultProductionLog()
defaultLoggerMu sync.RWMutex
)
Expand Down

0 comments on commit a747930

Please sign in to comment.