From 38e273597c283e607fd58199ed77890813f7c22c Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Thu, 23 Feb 2017 18:30:32 +0100 Subject: log: log full level names instead of mispelled "EROR", "DBUG" --- log/format.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'log/format.go') diff --git a/log/format.go b/log/format.go index 2a3790501..c61a4d82a 100644 --- a/log/format.go +++ b/log/format.go @@ -88,7 +88,7 @@ func TerminalFormat() Format { } b := &bytes.Buffer{} - lvl := strings.ToUpper(r.Lvl.String()) + lvl := r.Lvl.AlignedString() if atomic.LoadUint32(&locationEnabled) != 0 { // Log origin printing was requested, format the location path and line number location := fmt.Sprintf("%+v", r.Call) @@ -107,13 +107,13 @@ func TerminalFormat() Format { 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) } 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 { if color > 0 { fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s] %s ", color, lvl, r.Time.Format(termTimeFormat), r.Msg) } 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 -- cgit v1.2.3 From d0eba23af373bb54b00b242ccee4239fc9afd873 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Thu, 23 Feb 2017 19:31:13 +0100 Subject: all: disable log message colors outside of geth Also tweak behaviour so colors are only enabled when stderr is a terminal. --- log/format.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'log/format.go') diff --git a/log/format.go b/log/format.go index c61a4d82a..f32fcf744 100644 --- a/log/format.go +++ b/log/format.go @@ -69,22 +69,24 @@ func (f formatFunc) Format(r *Record) []byte { // // [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 { var color = 0 - switch r.Lvl { - case LvlCrit: - color = 35 - case LvlError: - color = 31 - case LvlWarn: - color = 33 - case LvlInfo: - color = 32 - case LvlDebug: - color = 36 - case LvlTrace: - color = 34 + if usecolor { + switch r.Lvl { + case LvlCrit: + color = 35 + case LvlError: + color = 31 + case LvlWarn: + color = 33 + case LvlInfo: + color = 32 + case LvlDebug: + color = 36 + case LvlTrace: + color = 34 + } } b := &bytes.Buffer{} -- cgit v1.2.3