From 436d68dedaecf5f486395a776d1ceb942606177d Mon Sep 17 00:00:00 2001 From: Justin Li <jli.justinli@gmail.com> Date: Sat, 15 Mar 2014 23:36:51 -0400 Subject: [PATCH 1/2] Add option to force TextFormatter to use colors --- text_formatter.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/text_formatter.go b/text_formatter.go index 5c50c91..4df816b 100644 --- a/text_formatter.go +++ b/text_formatter.go @@ -18,12 +18,14 @@ const ( ) type TextFormatter struct { + // Set to true to bypass checking for a TTY before outputting colors. + ForceColors bool } func (f *TextFormatter) Format(entry *Entry) ([]byte, error) { var serialized []byte - if ttyutils.IsTerminal(os.Stdout.Fd()) { + if f.ForceColors || ttyutils.IsTerminal(os.Stdout.Fd()) { levelText := strings.ToUpper(entry.Data["level"].(string))[0:4] levelColor := blue From cc1a5b95bc40b10211bc9672f953df5ded75fdba Mon Sep 17 00:00:00 2001 From: Justin Li <jli.justinli@gmail.com> Date: Sun, 16 Mar 2014 17:27:31 -0400 Subject: [PATCH 2/2] Add note about ForceColors in the README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 3443d32..93b1c49 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,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`. * `logrus.JSONFormatter`. Logs fields as JSON. Third party logging formatters: