diff options
author | Aziz Rmadi <[email protected]> | 2024-02-01 20:12:42 -0600 |
---|---|---|
committer | GitHub <[email protected]> | 2024-02-01 19:12:42 -0700 |
commit | a7479302fc0ce40e265fa02130d6f251e6b9de8c (patch) | |
tree | 4dd40e7b2dba7b52223d5249d78ec462c5ffe827 /logging.go | |
parent | 223f314331f430948b9149d4f150086945fe0040 (diff) | |
download | caddy-a7479302fc0ce40e265fa02130d6f251e6b9de8c.tar.gz caddy-a7479302fc0ce40e265fa02130d6f251e6b9de8c.zip |
core: Support NO_COLOR env var to disable log coloring (#6078)
Diffstat (limited to 'logging.go')
-rw-r--r-- | logging.go | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/logging.go b/logging.go index e1ee01509..a076f062c 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 ) |