Testing colormap
This commit is contained in:
parent
3aae310683
commit
fd56d7a420
|
@ -14,15 +14,15 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
red = 31
|
||||
yellow = 33
|
||||
blue = 34
|
||||
cyan = 36
|
||||
gray = 37
|
||||
green = 42
|
||||
RED = 31
|
||||
YELLOW = 33
|
||||
BLUE = 34
|
||||
CYAN = 36
|
||||
GRAY = 37
|
||||
GREEN = 42
|
||||
)
|
||||
|
||||
type ColorMap map[string]string
|
||||
type ColorMap map[string]int
|
||||
|
||||
var baseTimestamp time.Time
|
||||
|
||||
|
@ -32,6 +32,13 @@ func init() {
|
|||
|
||||
// TextFormatter formats logs into text
|
||||
type TextFormatter struct {
|
||||
// ColorMap allows users to customize the logging colors.
|
||||
// As an example:
|
||||
// formatter := &log.TextFormatter{
|
||||
// ColorMap: ColorMap{
|
||||
// "INFO": RED}}
|
||||
ColorMap map[string]int
|
||||
|
||||
// Set to true to bypass checking for a TTY before outputting colors.
|
||||
ForceColors bool
|
||||
|
||||
|
@ -103,15 +110,6 @@ type TextFormatter struct {
|
|||
|
||||
// The max length of the level text, generated dynamically on init
|
||||
levelTextMaxLength int
|
||||
|
||||
// ColorMap allows users to customize the logging level colors.
|
||||
// As an example:
|
||||
// formatter := &TextFormatter{
|
||||
// ColorMap: ColorMap{
|
||||
// "DEBUG": RED,
|
||||
// "INFO": GREEN,
|
||||
// }}
|
||||
ColorMap ColorMap
|
||||
}
|
||||
|
||||
func (f *TextFormatter) init(entry *Entry) {
|
||||
|
@ -244,7 +242,15 @@ func (f *TextFormatter) Format(entry *Entry) ([]byte, error) {
|
|||
|
||||
func (f *TextFormatter) printColored(b *bytes.Buffer, entry *Entry, keys []string, data Fields, timestampFormat string) {
|
||||
levelText := strings.ToUpper(entry.Level.String())
|
||||
//fmt.Println(levelText)
|
||||
//fmt.Println(f.ColorMap[levelText])
|
||||
//fmt.Println(f.INFO)
|
||||
//levelColor := RED
|
||||
levelColor := f.ColorMap[levelText]
|
||||
//fmt.Println(levelColor)
|
||||
//fmt.Printf("%s\n", reflect.TypeOf(levelColor))
|
||||
//fmt.Printf("%s\n", reflect.TypeOf(RED))
|
||||
//fmt.Println(RED)
|
||||
if !f.DisableLevelTruncation && !f.PadLevelText {
|
||||
levelText = levelText[0:4]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue