Skip to content

Commit

Permalink
Only set CanColorStdout / CanColorStderr to true if the stdout/stderr…
Browse files Browse the repository at this point in the history
… is a terminal (#19581)
  • Loading branch information
wxiaoguang authored May 3, 2022
1 parent 982b726 commit 730420b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions modules/log/console_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build !windows

package log

import (
"os"

"github.com/mattn/go-isatty"
)

func init() {
// when running gitea as a systemd unit with logging set to console, the output can not be colorized,
// otherwise it spams the journal / syslog with escape sequences like "#033[0m#033[32mcmd/web.go:102:#033[32m"
// this file covers non-windows platforms.
CanColorStdout = isatty.IsTerminal(os.Stdout.Fd())
CanColorStderr = isatty.IsTerminal(os.Stderr.Fd())
}

0 comments on commit 730420b

Please sign in to comment.