Testing colormap
This commit is contained in:
parent
74926d1078
commit
92bd89cdd5
|
@ -184,10 +184,3 @@ type Ext1FieldLogger interface {
|
|||
Trace(args ...interface{})
|
||||
Traceln(args ...interface{})
|
||||
}
|
||||
|
||||
type ColorMap map[string]int
|
||||
|
||||
var colorMap = ColorMap{
|
||||
"INFO": RED,
|
||||
"DEBUG": BLUE,
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@ const (
|
|||
GREEN = 42
|
||||
)
|
||||
|
||||
type ColorMap map[string]string
|
||||
|
||||
var baseTimestamp time.Time
|
||||
|
||||
func init() {
|
||||
|
@ -30,6 +32,8 @@ func init() {
|
|||
|
||||
// TextFormatter formats logs into text
|
||||
type TextFormatter struct {
|
||||
ColorMap map[string]int
|
||||
|
||||
// Set to true to bypass checking for a TTY before outputting colors.
|
||||
ForceColors bool
|
||||
|
||||
|
@ -101,16 +105,6 @@ type TextFormatter struct {
|
|||
|
||||
// The max length of the level text, generated dynamically on init
|
||||
levelTextMaxLength int
|
||||
|
||||
// ColorMap allows users to control colors for logging levels.
|
||||
// As an example:
|
||||
// formatter := &TextFormatter{
|
||||
// ColorMap: ColorMap{
|
||||
// "Debug": red,
|
||||
// "Info": blue,
|
||||
// },
|
||||
// }
|
||||
ColorMap ColorMap
|
||||
}
|
||||
|
||||
func (f *TextFormatter) init(entry *Entry) {
|
||||
|
@ -243,7 +237,7 @@ 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())
|
||||
levelColor := colorMap[levelText]
|
||||
levelColor := f.ColorMap[levelText]
|
||||
if !f.DisableLevelTruncation && !f.PadLevelText {
|
||||
levelText = levelText[0:4]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue