Skip to content

Commit ae61992

Browse files
wxiaoguangAbdulrhmnGhanem
authored andcommitted
Only set CanColorStdout / CanColorStderr to true if the stdout/stderr is a terminal (go-gitea#19581)
1 parent 61a8b48 commit ae61992

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

modules/log/console_other.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build !windows
6+
7+
package log
8+
9+
import (
10+
"os"
11+
12+
"github.com/mattn/go-isatty"
13+
)
14+
15+
func init() {
16+
// when running gitea as a systemd unit with logging set to console, the output can not be colorized,
17+
// otherwise it spams the journal / syslog with escape sequences like "#033[0m#033[32mcmd/web.go:102:#033[32m"
18+
// this file covers non-windows platforms.
19+
CanColorStdout = isatty.IsTerminal(os.Stdout.Fd())
20+
CanColorStderr = isatty.IsTerminal(os.Stderr.Fd())
21+
}

0 commit comments

Comments
 (0)