Repository: caddyserver/caddy (language: go)

Issue:
Add support for disabling ANSI color output
Add support for disabling ANSI color output by default or with the [`NO_COLOR='1'` environment variable](https://no-color.org).

ANSI color output does not play well with capturing the output to a text file nor is well supported in Windows.


Discussion / hints:

Fix patch:
diff --git a/logging.go b/logging.go
index e1ee015093e..a076f062c7d 100644
--- a/logging.go
+++ b/logging.go
@@ -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
 )


Test patch: