aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2017-02-24 01:30:32 +0800
committerFelix Lange <fjl@twurst.com>2017-02-27 22:32:48 +0800
commit38e273597c283e607fd58199ed77890813f7c22c (patch)
treededbca610c717eb2a722c3edd84d57b5bfcdaebf
parente8b3e226124d2b0234c36ef2ca9221dc95c56a1a (diff)
downloaddexon-38e273597c283e607fd58199ed77890813f7c22c.tar
dexon-38e273597c283e607fd58199ed77890813f7c22c.tar.gz
dexon-38e273597c283e607fd58199ed77890813f7c22c.tar.bz2
dexon-38e273597c283e607fd58199ed77890813f7c22c.tar.lz
dexon-38e273597c283e607fd58199ed77890813f7c22c.tar.xz
dexon-38e273597c283e607fd58199ed77890813f7c22c.tar.zst
dexon-38e273597c283e607fd58199ed77890813f7c22c.zip
log: log full level names instead of mispelled "EROR", "DBUG"
-rw-r--r--log/format.go6
-rw-r--r--log/logger.go22
2 files changed, 24 insertions, 4 deletions
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
diff --git a/log/logger.go b/log/logger.go
index a7f7d9df7..15c83a9b2 100644
--- a/log/logger.go
+++ b/log/logger.go
@@ -24,7 +24,27 @@ const (
LvlTrace
)
-// Returns the name of a Lvl
+// Aligned returns a 5-character string containing the name of a Lvl.
+func (l Lvl) AlignedString() string {
+ switch l {
+ case LvlTrace:
+ return "TRACE"
+ case LvlDebug:
+ return "DEBUG"
+ case LvlInfo:
+ return "INFO "
+ case LvlWarn:
+ return "WARN "
+ case LvlError:
+ return "ERROR"
+ case LvlCrit:
+ return "CRIT "
+ default:
+ panic("bad level")
+ }
+}
+
+// Strings returns the name of a Lvl.
func (l Lvl) String() string {
switch l {
case LvlTrace: