MCPcopy
hub / github.com/sirupsen/logrus / TestFieldClashWithCaller

Function TestFieldClashWithCaller

json_formatter_test.go:291–318  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

289}
290
291func TestFieldClashWithCaller(t *testing.T) {
292 SetReportCaller(true)
293 formatter := &JSONFormatter{}
294 e := WithField("func", "howdy pardner")
295 e.Caller = &runtime.Frame{Function: "somefunc"}
296 b, err := formatter.Format(e)
297 if err != nil {
298 t.Fatal("Unable to format entry: ", err)
299 }
300
301 entry := make(map[string]interface{})
302 err = json.Unmarshal(b, &entry)
303 if err != nil {
304 t.Fatal("Unable to unmarshal formatted entry: ", err)
305 }
306
307 if entry["fields.func"] != "howdy pardner" {
308 t.Fatalf("fields.func not set to original func field when ReportCaller=true (got '%s')",
309 entry["fields.func"])
310 }
311
312 if entry["func"] != "somefunc" {
313 t.Fatalf("func not set as expected when ReportCaller=true (got '%s')",
314 entry["func"])
315 }
316
317 SetReportCaller(false) // return to default value
318}
319
320func TestJSONDisableTimestamp(t *testing.T) {
321 formatter := &JSONFormatter{

Callers

nothing calls this directly

Calls 5

FormatMethod · 0.95
SetReportCallerFunction · 0.85
WithFieldFunction · 0.85
FatalMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected