Add String() func to Threshold
diff --git a/notepad.go b/notepad.go index ea34586..a35d7a8 100644 --- a/notepad.go +++ b/notepad.go
@@ -14,6 +14,10 @@ type Threshold int +func (t Threshold) String() string { + return prefixes[t] +} + const ( LevelTrace Threshold = iota LevelDebug @@ -25,13 +29,17 @@ ) var prefixes map[Threshold]string = map[Threshold]string{ - LevelTrace: "TRACE ", - LevelDebug: "DEBUG ", - LevelInfo: "INFO ", - LevelWarn: "WARN ", - LevelError: "ERROR ", - LevelCritical: "CRITICAL ", - LevelFatal: "FATAL ", + LevelTrace: "TRACE", + LevelDebug: "DEBUG", + LevelInfo: "INFO", + LevelWarn: "WARN", + LevelError: "ERROR", + LevelCritical: "CRITICAL", + LevelFatal: "FATAL", +} + +func prefix(t Threshold) string { + return t.String() + " " } // Notepad is where you leave a note ! @@ -106,16 +114,16 @@ switch { case threshold >= n.logThreshold && threshold >= n.stdoutThreshold: - *logger = log.New(io.MultiWriter(counter, bothHandle), n.prefix+prefixes[threshold], n.flags) + *logger = log.New(io.MultiWriter(counter, bothHandle), n.prefix+prefix(threshold), n.flags) case threshold >= n.logThreshold: - *logger = log.New(io.MultiWriter(counter, n.logHandle), n.prefix+prefixes[threshold], n.flags) + *logger = log.New(io.MultiWriter(counter, n.logHandle), n.prefix+prefix(threshold), n.flags) case threshold >= n.stdoutThreshold: - *logger = log.New(io.MultiWriter(counter, os.Stdout), n.prefix+prefixes[threshold], n.flags) + *logger = log.New(io.MultiWriter(counter, os.Stdout), n.prefix+prefix(threshold), n.flags) default: - *logger = log.New(counter, n.prefix+prefixes[threshold], n.flags) + *logger = log.New(counter, n.prefix+prefix(threshold), n.flags) } } }
diff --git a/notepad_test.go b/notepad_test.go index 7f6739b..66a3cf4 100644 --- a/notepad_test.go +++ b/notepad_test.go
@@ -31,3 +31,8 @@ require.Equal(t, n.LogCountForLevel(LevelDebug), uint64(1)) require.Equal(t, n.LogCountForLevel(LevelTrace), uint64(0)) } + +func TestThresholdString(t *testing.T) { + require.Equal(t, LevelError.String(), "ERROR") + require.Equal(t, LevelTrace.String(), "TRACE") +}