TUN-3195: Don't colorize console logs when stderr is not a terminal

This commit is contained in:
Igor Postelnik
2021-01-21 17:03:47 -06:00
parent a129572749
commit ce22dd681a
230 changed files with 13100 additions and 5789 deletions

View File

@@ -12,6 +12,7 @@ import (
"github.com/rs/zerolog"
fallbacklog "github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
"golang.org/x/term"
"gopkg.in/natefinch/lumberjack.v2"
)
@@ -138,9 +139,10 @@ func Create(loggerConfig *Config) *zerolog.Logger {
}
func createConsoleLogger(config ConsoleConfig) io.Writer {
consoleOut := os.Stderr
return zerolog.ConsoleWriter{
Out: colorable.NewColorableStderr(),
NoColor: config.noColor,
Out: colorable.NewColorable(consoleOut),
NoColor: config.noColor || !term.IsTerminal(int(consoleOut.Fd())),
}
}