From af9d545893db51f0257b1f7b068411858553420b Mon Sep 17 00:00:00 2001 From: Matt Price Date: Wed, 13 Aug 2014 13:30:25 -0400 Subject: [PATCH 1/3] can completely disable colors on text formatter --- text_formatter.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/text_formatter.go b/text_formatter.go index d71eba1..114723d 100644 --- a/text_formatter.go +++ b/text_formatter.go @@ -26,7 +26,8 @@ func miniTS() int { type TextFormatter struct { // Set to true to bypass checking for a TTY before outputting colors. - ForceColors bool + ForceColors bool + DisableColors bool } func (f *TextFormatter) Format(entry *Entry) ([]byte, error) { @@ -34,7 +35,7 @@ func (f *TextFormatter) Format(entry *Entry) ([]byte, error) { prefixFieldClashes(entry) - if f.ForceColors || IsTerminal() { + if (f.ForceColors || IsTerminal()) && !DisableColors { levelText := strings.ToUpper(entry.Data["level"].(string))[0:4] levelColor := blue From e2a44689a6ce3863ae1a4f051a2fc550dfb6f82b Mon Sep 17 00:00:00 2001 From: Matt Price Date: Wed, 13 Aug 2014 13:36:59 -0400 Subject: [PATCH 2/3] updated README and added reference --- README.md | 1 + text_formatter.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3a6aced..3560b70 100644 --- a/README.md +++ b/README.md @@ -296,6 +296,7 @@ The built-in logging formatters are: without colors. * *Note:* to force colored output when there is no TTY, set the `ForceColors` field to `true`. + * *Note:* to force no colored output set the `DisableColors` field to `true` * `logrus.JSONFormatter`. Logs fields as JSON. Third party logging formatters: diff --git a/text_formatter.go b/text_formatter.go index 114723d..4b93690 100644 --- a/text_formatter.go +++ b/text_formatter.go @@ -35,7 +35,7 @@ func (f *TextFormatter) Format(entry *Entry) ([]byte, error) { prefixFieldClashes(entry) - if (f.ForceColors || IsTerminal()) && !DisableColors { + if (f.ForceColors || IsTerminal()) && !f.DisableColors { levelText := strings.ToUpper(entry.Data["level"].(string))[0:4] levelColor := blue From cc9d1426337bf50e7fbd22c36bd1d13af9e2c83e Mon Sep 17 00:00:00 2001 From: Matt Price Date: Thu, 14 Aug 2014 18:04:57 -0400 Subject: [PATCH 3/3] cleaned up Readme details --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3560b70..1bb715e 100644 --- a/README.md +++ b/README.md @@ -295,8 +295,8 @@ The built-in logging formatters are: * `logrus.TextFormatter`. Logs the event in colors if stdout is a tty, otherwise without colors. * *Note:* to force colored output when there is no TTY, set the `ForceColors` - field to `true`. - * *Note:* to force no colored output set the `DisableColors` field to `true` + field to `true`. To force no colored output even if there is a TTY set the + `DisableColors` field to `true` * `logrus.JSONFormatter`. Logs fields as JSON. Third party logging formatters: