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: diff --git a/text_formatter.go b/text_formatter.go index d481686..95c3264 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