Skip to content

Commit a747930

Browse files
authored
core: Support NO_COLOR env var to disable log coloring (#6078)
1 parent 223f314 commit a747930

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

logging.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,10 @@ func newDefaultProductionLogEncoder(wo WriterOpener) zapcore.Encoder {
717717
encCfg.EncodeTime = func(ts time.Time, encoder zapcore.PrimitiveArrayEncoder) {
718718
encoder.AppendString(ts.UTC().Format("2006/01/02 15:04:05.000"))
719719
}
720-
encCfg.EncodeLevel = zapcore.CapitalColorLevelEncoder
720+
if coloringEnabled {
721+
encCfg.EncodeLevel = zapcore.CapitalColorLevelEncoder
722+
}
723+
721724
return zapcore.NewConsoleEncoder(encCfg)
722725
}
723726
return zapcore.NewJSONEncoder(encCfg)
@@ -758,6 +761,7 @@ func Log() *zap.Logger {
758761
}
759762

760763
var (
764+
coloringEnabled = os.Getenv("NO_COLOR") == "" && os.Getenv("TERM") != "xterm-mono"
761765
defaultLogger, _ = newDefaultProductionLog()
762766
defaultLoggerMu sync.RWMutex
763767
)

0 commit comments

Comments
 (0)