Skip to content

Commit

Permalink
internal/apmlog: fix log levels (#860)
Browse files Browse the repository at this point in the history
- Add the "trace" level.
- In addition to "warn", we should also accept "warning".
  • Loading branch information
axw authored Dec 14, 2020
1 parent 491755f commit 0a73d5b
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions internal/apmlog/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ func InitDefaultLogger() {

// Log levels.
const (
DebugLevel Level = iota
TraceLevel Level = iota
DebugLevel
InfoLevel
WarnLevel
WarningLevel
ErrorLevel
CriticalLevel
OffLevel
Expand All @@ -107,27 +108,37 @@ type Level uint32

func (l Level) String() string {
switch l {
case TraceLevel:
return "trace"
case DebugLevel:
return "debug"
case InfoLevel:
return "info"
case WarnLevel:
return "warn"
case WarningLevel:
return "warning"
case ErrorLevel:
return "error"
case CriticalLevel:
return "critical"
case OffLevel:
return "off"
}
return ""
}

// ParseLogLevel parses s as a log level.
func ParseLogLevel(s string) (Level, error) {
switch strings.ToLower(s) {
case "trace":
return TraceLevel, nil
case "debug":
return DebugLevel, nil
case "info":
return InfoLevel, nil
case "warn":
return WarnLevel, nil
case "warn", "warning":
// "warn" exists for backwards compatibility;
// "warning" is the canonical level name.
return WarningLevel, nil
case "error":
return ErrorLevel, nil
case "critical":
Expand Down Expand Up @@ -167,7 +178,7 @@ func (l *LevelLogger) Errorf(format string, args ...interface{}) {

// Warningf logs a message with log.Printf, with a WARNING prefix.
func (l *LevelLogger) Warningf(format string, args ...interface{}) {
l.logf(WarnLevel, format, args...)
l.logf(WarningLevel, format, args...)
}

func (l *LevelLogger) logf(level Level, format string, args ...interface{}) {
Expand Down

0 comments on commit 0a73d5b

Please sign in to comment.