Skip to content

Commit

Permalink
Merge pull request #4 from mbyczkowski/master
Browse files Browse the repository at this point in the history
Make formatter compatible with logrus >= 0.11.1
  • Loading branch information
x-cray committed Feb 8, 2017
2 parents a35e641 + 90fb250 commit f8f0b43
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"bytes"
"fmt"
"regexp"
"runtime"
"sort"
"strings"
"sync"
"time"

"github.com/Sirupsen/logrus"
Expand All @@ -17,12 +17,10 @@ const reset = ansi.Reset

var (
baseTimestamp time.Time
isTerminal bool
)

func init() {
baseTimestamp = time.Now()
isTerminal = logrus.IsTerminal()
}

func miniTS() int {
Expand Down Expand Up @@ -55,6 +53,10 @@ type TextFormatter struct {
// The value for this parameter will be the size of padding.
// Its default value is zero, which means no padding will be applied for msg.
SpacePadding int

// Whether the logger's out is to a terminal
isTerminal bool
terminalOnce sync.Once
}

func (f *TextFormatter) Format(entry *logrus.Entry) ([]byte, error) {
Expand All @@ -73,8 +75,13 @@ func (f *TextFormatter) Format(entry *logrus.Entry) ([]byte, error) {

prefixFieldClashes(entry.Data)

isColorTerminal := isTerminal && (runtime.GOOS != "windows")
isColored := (f.ForceColors || isColorTerminal) && !f.DisableColors
f.terminalOnce.Do(func() {
if entry.Logger != nil {
f.isTerminal = logrus.IsTerminal(entry.Logger.Out)
}
})

isColored := (f.ForceColors || f.isTerminal) && !f.DisableColors

timestampFormat := f.TimestampFormat
if timestampFormat == "" {
Expand Down

0 comments on commit f8f0b43

Please sign in to comment.