@marcel91200 / caddy Mirror · read-only / commits / a7479302
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 12, 18:15 UTC

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

Aziz Rmadi committed Feb 1, 2024 at 20:12 UTC a7479302fc0ce40e265fa02130d6f251e6b9de8c
1 file changed +5 -1
logging.go
+5 -1
@@ -717,7 +717,10 @@ func newDefaultProductionLogEncoder(wo WriterOpener) zapcore.Encoder {
717 encCfg.EncodeTime = func(ts time.Time, encoder zapcore.PrimitiveArrayEncoder) {
718 encoder.AppendString(ts.UTC().Format("2006/01/02 15:04:05.000"))
719 }
720 - encCfg.EncodeLevel = zapcore.CapitalColorLevelEncoder
720 + if coloringEnabled {
721 + encCfg.EncodeLevel = zapcore.CapitalColorLevelEncoder
722 + }
723 +
724 return zapcore.NewConsoleEncoder(encCfg)
725 }
726 return zapcore.NewJSONEncoder(encCfg)
@@ -758,6 +761,7 @@ func Log() *zap.Logger {
761 }
762
763 var (
764 + coloringEnabled = os.Getenv("NO_COLOR") == "" && os.Getenv("TERM") != "xterm-mono"
765 defaultLogger, _ = newDefaultProductionLog()
766 defaultLoggerMu sync.RWMutex
767 )