Add Trace level logging

This commit is contained in:
Giedrius Dubinskas 2017-10-02 19:38:29 +03:00 committed by Loren Osborn
parent 4981d8161c
commit c7a33dc5de
3 changed files with 13 additions and 3 deletions

View File

@ -122,7 +122,7 @@ func Fatal(args ...interface{}) {
std.Fatal(args...) std.Fatal(args...)
} }
// Tracef logs a message at level Debug on the standard logger. // Tracef logs a message at level Trace on the standard logger.
func Tracef(format string, args ...interface{}) { func Tracef(format string, args ...interface{}) {
std.Tracef(format, args...) std.Tracef(format, args...)
} }
@ -167,7 +167,7 @@ func Fatalf(format string, args ...interface{}) {
std.Fatalf(format, args...) std.Fatalf(format, args...)
} }
// Traceln logs a message at level Debug on the standard logger. // Traceln logs a message at level Trace on the standard logger.
func Traceln(args ...interface{}) { func Traceln(args ...interface{}) {
std.Traceln(args...) std.Traceln(args...)
} }

View File

@ -87,7 +87,8 @@ const (
InfoLevel InfoLevel
// DebugLevel level. Usually only enabled when debugging. Very verbose logging. // DebugLevel level. Usually only enabled when debugging. Very verbose logging.
DebugLevel DebugLevel
// TraceLevel level. Usually only enabled when debugging. Very verbose logging. Usually reserved for message traces // TraceLevel level. Usually only enabled when debugging. Very verbose logging.
// Usually reserved for message traces.
TraceLevel TraceLevel
) )

View File

@ -303,6 +303,7 @@ func TestDoubleLoggingDoesntPrefixPreviousFields(t *testing.T) {
} }
func TestConvertLevelToString(t *testing.T) { func TestConvertLevelToString(t *testing.T) {
assert.Equal(t, "trace", TraceLevel.String())
assert.Equal(t, "debug", DebugLevel.String()) assert.Equal(t, "debug", DebugLevel.String())
assert.Equal(t, "info", InfoLevel.String()) assert.Equal(t, "info", InfoLevel.String())
assert.Equal(t, "warning", WarnLevel.String()) assert.Equal(t, "warning", WarnLevel.String())
@ -368,6 +369,14 @@ func TestParseLevel(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, DebugLevel, l) assert.Equal(t, DebugLevel, l)
l, err = ParseLevel("trace")
assert.Nil(t, err)
assert.Equal(t, TraceLevel, l)
l, err = ParseLevel("TRACE")
assert.Nil(t, err)
assert.Equal(t, TraceLevel, l)
l, err = ParseLevel("invalid") l, err = ParseLevel("invalid")
assert.Equal(t, "not a valid logrus Level: \"invalid\"", err.Error()) assert.Equal(t, "not a valid logrus Level: \"invalid\"", err.Error())
} }