mirror of
https://github.com/zrepl/zrepl.git
synced 2025-08-12 16:27:05 +02:00
colorized stdout logger if stdout is tty
This commit is contained in:
@ -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.
|
||||
|
Reference in New Issue
Block a user