levels: add string helper

This commit is contained in:
Simon Eskildsen 2014-07-26 21:02:08 -04:00
parent 6be56e6e50
commit cd8fc638cc
3 changed files with 30 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
logrus

View File

@ -10,6 +10,26 @@ type Fields map[string]interface{}
// Level type // Level type
type Level uint8 type Level uint8
// Convert the Level to a string. E.g. PanicLevel becomes "panic".
func (level Level) String() string {
switch level {
case DebugLevel:
return "debug"
case InfoLevel:
return "info"
case WarnLevel:
return "warning"
case ErrorLevel:
return "error"
case FatalLevel:
return "fatal"
case PanicLevel:
return "panic"
}
return "unknown"
}
// These are the different logging levels. You can set the logging level to log // These are the different logging levels. You can set the logging level to log
// on your instance of logger, obtained with `logrus.New()`. // on your instance of logger, obtained with `logrus.New()`.
const ( const (

View File

@ -128,3 +128,12 @@ func TestWithFieldsShouldAllowAssignments(t *testing.T) {
assert.Equal(t, false, ok) assert.Equal(t, false, ok)
assert.Equal(t, "value1", fields["key1"]) assert.Equal(t, "value1", fields["key1"])
} }
func TestConvertLevelToString(t *testing.T) {
assert.Equal(t, "debug", DebugLevel.String())
assert.Equal(t, "info", InfoLevel.String())
assert.Equal(t, "warning", WarnLevel.String())
assert.Equal(t, "error", ErrorLevel.String())
assert.Equal(t, "fatal", FatalLevel.String())
assert.Equal(t, "panic", PanicLevel.String())
}