Skip to content

Commit

Permalink
log: log full level names instead of mispelled "EROR", "DBUG"
Browse files Browse the repository at this point in the history
  • Loading branch information
fjl committed Feb 27, 2017
1 parent e8b3e22 commit 38e2735
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
6 changes: 3 additions & 3 deletions log/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
22 changes: 21 additions & 1 deletion log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 38e2735

Please sign in to comment.