Skip to content

Commit

Permalink
Allow to disable color in the text formatter
Browse files Browse the repository at this point in the history
This commit adds support for NO_COLOR environment variable, if this is
set, colors will be disabled in the logrus text formatter.

This commit also adds support for the environment variables supported by
logrus, CLICOLOR and CLICOLOR_FORCE

Related to #1549
  • Loading branch information
maraino committed Sep 26, 2023
1 parent b66a92c commit 00d8d8f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions logging/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package logging
import (
"encoding/json"
"net/http"
"os"
"strings"

"github.com/pkg/errors"
Expand Down Expand Up @@ -38,6 +39,13 @@ func New(name string, raw json.RawMessage) (*Logger, error) {
var formatter logrus.Formatter
switch strings.ToLower(config.Format) {
case "", "text":
_, noColor := os.LookupEnv("NO_COLOR")
// With EnvironmentOverrideColors set, logrus looks at CLICOLOR and
// CLICOLOR_FORCE
formatter = &logrus.TextFormatter{
DisableColors: noColor,
EnvironmentOverrideColors: true,
}
case "json":
formatter = new(logrus.JSONFormatter)
case "common":
Expand Down

0 comments on commit 00d8d8f

Please sign in to comment.