tlog: only enable color if both stderr and stdout are a terminal

This

    gocryptfs -init /does/not/exist 2> err.log

used to write escape codes into err.log. Stop doing that.
This commit is contained in:
Jakob Unterwurzacher 2021-12-11 15:37:13 +01:00
parent a1f01419e2
commit eb42e54182
1 changed files with 3 additions and 1 deletions

View File

@ -108,7 +108,9 @@ var Fatal *toggledLogger
func init() {
// Enable color output if we are connected to a terminal and NO_COLOR is
// unset ( https://no-color.org/ ).
if _, nocolor := os.LookupEnv("NO_COLOR"); !nocolor && term.IsTerminal(int(os.Stdout.Fd())) {
if _, nocolor := os.LookupEnv("NO_COLOR"); !nocolor &&
term.IsTerminal(int(os.Stdout.Fd())) &&
term.IsTerminal(int(os.Stderr.Fd())) {
ColorReset = "\033[0m"
ColorGrey = "\033[2m"
ColorRed = "\033[31m"