colorized stdout logger if stdout is tty

This commit is contained in:
Christian Schwarz
2018-08-30 13:30:18 +02:00
parent b5957aca37
commit 1690339440
6 changed files with 51 additions and 9 deletions

View File

@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/fatih/color"
"github.com/pkg/errors"
"sync"
"time"
@ -105,6 +106,21 @@ type Entry struct {
Fields Fields
}
func (e Entry) Color() *color.Color {
c := color.New()
switch e.Level {
case Debug:
c.Add(color.FgHiBlue)
case Info:
c.Add(color.FgHiGreen)
case Warn:
c.Add(color.FgHiYellow)
case Error:
c.Add(color.FgHiRed)
}
return c
}
// An outlet receives log entries produced by the Logger and writes them to some destination.
type Outlet interface {
// Write the entry to the destination.