Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ type Formatter struct {
// NoColors - disable colors
NoColors bool

// ColorTimestamp - enables log level colors for timestamp
ColorTimestamp bool

// NoFieldsColors - apply colors only to the level, default is level + fields
NoFieldsColors bool

Expand Down Expand Up @@ -59,9 +62,17 @@ func (f *Formatter) Format(entry *logrus.Entry) ([]byte, error) {
// output buffer
b := &bytes.Buffer{}

if f.ColorTimestamp {
fmt.Fprintf(b, "\x1b[%dm", levelColor)
}

// write time
b.WriteString(entry.Time.Format(timestampFormat))

if f.ColorTimestamp {
b.WriteString("\x1b[0m")
}

// write level
var level string
if f.NoUppercaseLevel {
Expand Down