|
|
@ -69,26 +69,28 @@ func (f formatFunc) Format(r *Record) []byte { |
|
|
|
//
|
|
|
|
//
|
|
|
|
// [May 16 20:58:45] [DBUG] remove route ns=haproxy addr=127.0.0.1:50002
|
|
|
|
// [May 16 20:58:45] [DBUG] remove route ns=haproxy addr=127.0.0.1:50002
|
|
|
|
//
|
|
|
|
//
|
|
|
|
func TerminalFormat() Format { |
|
|
|
func TerminalFormat(usecolor bool) Format { |
|
|
|
return FormatFunc(func(r *Record) []byte { |
|
|
|
return FormatFunc(func(r *Record) []byte { |
|
|
|
var color = 0 |
|
|
|
var color = 0 |
|
|
|
switch r.Lvl { |
|
|
|
if usecolor { |
|
|
|
case LvlCrit: |
|
|
|
switch r.Lvl { |
|
|
|
color = 35 |
|
|
|
case LvlCrit: |
|
|
|
case LvlError: |
|
|
|
color = 35 |
|
|
|
color = 31 |
|
|
|
case LvlError: |
|
|
|
case LvlWarn: |
|
|
|
color = 31 |
|
|
|
color = 33 |
|
|
|
case LvlWarn: |
|
|
|
case LvlInfo: |
|
|
|
color = 33 |
|
|
|
color = 32 |
|
|
|
case LvlInfo: |
|
|
|
case LvlDebug: |
|
|
|
color = 32 |
|
|
|
color = 36 |
|
|
|
case LvlDebug: |
|
|
|
case LvlTrace: |
|
|
|
color = 36 |
|
|
|
color = 34 |
|
|
|
case LvlTrace: |
|
|
|
|
|
|
|
color = 34 |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
b := &bytes.Buffer{} |
|
|
|
b := &bytes.Buffer{} |
|
|
|
lvl := strings.ToUpper(r.Lvl.String()) |
|
|
|
lvl := r.Lvl.AlignedString() |
|
|
|
if atomic.LoadUint32(&locationEnabled) != 0 { |
|
|
|
if atomic.LoadUint32(&locationEnabled) != 0 { |
|
|
|
// Log origin printing was requested, format the location path and line number
|
|
|
|
// Log origin printing was requested, format the location path and line number
|
|
|
|
location := fmt.Sprintf("%+v", r.Call) |
|
|
|
location := fmt.Sprintf("%+v", r.Call) |
|
|
@ -107,13 +109,13 @@ func TerminalFormat() Format { |
|
|
|
if color > 0 { |
|
|
|
if color > 0 { |
|
|
|
fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s|%s]%s %s ", color, lvl, r.Time.Format(termTimeFormat), location, padding, r.Msg) |
|
|
|
fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s|%s]%s %s ", color, lvl, r.Time.Format(termTimeFormat), location, padding, r.Msg) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
fmt.Fprintf(b, "[%s] [%s|%s]%s %s ", lvl, r.Time.Format(termTimeFormat), location, padding, r.Msg) |
|
|
|
fmt.Fprintf(b, "%s[%s|%s]%s %s ", lvl, r.Time.Format(termTimeFormat), location, padding, r.Msg) |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if color > 0 { |
|
|
|
if color > 0 { |
|
|
|
fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s] %s ", color, lvl, r.Time.Format(termTimeFormat), r.Msg) |
|
|
|
fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s] %s ", color, lvl, r.Time.Format(termTimeFormat), r.Msg) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
fmt.Fprintf(b, "[%s] [%s] %s ", lvl, r.Time.Format(termTimeFormat), r.Msg) |
|
|
|
fmt.Fprintf(b, "%s[%s] %s ", lvl, r.Time.Format(termTimeFormat), r.Msg) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// try to justify the log output for short messages
|
|
|
|
// try to justify the log output for short messages
|
|
|
|