Add a CallerPrettyfier callback to the text formatter

This commit is contained in:
David Bariod
2019-02-27 13:34:02 +01:00
parent 5e9b246bea
commit ffec2f2e0a
3 changed files with 36 additions and 5 deletions
+11
View File
@@ -53,6 +53,17 @@ func TestReportCallerWhenConfigured(t *testing.T) {
assert.Equal(t, "somekindoffunc", fields[FieldKeyFunc])
assert.Equal(t, "thisisafilename", fields[FieldKeyFile])
})
LogAndAssertText(t, func(log *Logger) {
log.ReportCaller = true
log.Formatter.(*TextFormatter).CallerPrettyfier = func(f *runtime.Frame) (string, string) {
return "somekindoffunc", "thisisafilename"
}
log.Print("testWithCallerPrettyfier")
}, func(fields map[string]string) {
assert.Equal(t, "somekindoffunc", fields[FieldKeyFunc])
assert.Equal(t, "thisisafilename", fields[FieldKeyFile])
})
}
func logSomething(t *testing.T, message string) Fields {