Testing colormap
This commit is contained in:
parent
e0d45114e8
commit
9607740da9
2
go.mod
2
go.mod
|
@ -6,4 +6,4 @@ require (
|
|||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8
|
||||
)
|
||||
|
||||
go 1.13
|
||||
go 1.22
|
||||
|
|
|
@ -16,7 +16,8 @@ import (
|
|||
const (
|
||||
red = 31
|
||||
yellow = 33
|
||||
blue = 36
|
||||
blue = 34
|
||||
cyan = 36
|
||||
gray = 37
|
||||
)
|
||||
|
||||
|
@ -26,6 +27,8 @@ func init() {
|
|||
baseTimestamp = time.Now()
|
||||
}
|
||||
|
||||
type ColorMap map[string]int
|
||||
|
||||
// TextFormatter formats logs into text
|
||||
type TextFormatter struct {
|
||||
// Set to true to bypass checking for a TTY before outputting colors.
|
||||
|
@ -99,6 +102,8 @@ type TextFormatter struct {
|
|||
|
||||
// The max length of the level text, generated dynamically on init
|
||||
levelTextMaxLength int
|
||||
|
||||
ColorMap ColorMap
|
||||
}
|
||||
|
||||
func (f *TextFormatter) init(entry *Entry) {
|
||||
|
@ -231,18 +236,7 @@ func (f *TextFormatter) Format(entry *Entry) ([]byte, error) {
|
|||
|
||||
func (f *TextFormatter) printColored(b *bytes.Buffer, entry *Entry, keys []string, data Fields, timestampFormat string) {
|
||||
var levelColor int
|
||||
switch entry.Level {
|
||||
case DebugLevel, TraceLevel:
|
||||
levelColor = red
|
||||
case WarnLevel:
|
||||
levelColor = yellow
|
||||
case ErrorLevel, FatalLevel, PanicLevel:
|
||||
levelColor = red
|
||||
case InfoLevel:
|
||||
levelColor = blue
|
||||
default:
|
||||
levelColor = blue
|
||||
}
|
||||
levelColor = ColorMap[entry.Level]
|
||||
|
||||
levelText := strings.ToUpper(entry.Level.String())
|
||||
if !f.DisableLevelTruncation && !f.PadLevelText {
|
||||
|
|
Loading…
Reference in New Issue
Block a user