Add option to force TextFormatter to use colors

This commit is contained in:
Justin Li 2014-03-15 23:36:51 -04:00
parent f33bbddc25
commit 436d68deda
1 changed files with 3 additions and 1 deletions

View File

@ -18,12 +18,14 @@ const (
) )
type TextFormatter struct { 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) { func (f *TextFormatter) Format(entry *Entry) ([]byte, error) {
var serialized []byte 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] levelText := strings.ToUpper(entry.Data["level"].(string))[0:4]
levelColor := blue levelColor := blue