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

Function TestDoubleLoggingDoesntPrefixPreviousFields

logrus_test.go:330–360  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

328}
329
330func TestDoubleLoggingDoesntPrefixPreviousFields(t *testing.T) {
331
332 var buffer bytes.Buffer
333 var fields Fields
334
335 logger := New()
336 logger.Out = &buffer
337 logger.Formatter = new(JSONFormatter)
338
339 llog := logger.WithField("context", "eating raw fish")
340
341 llog.Info("looks delicious")
342
343 err := json.Unmarshal(buffer.Bytes(), &fields)
344 require.NoError(t, err, "should have decoded first message")
345 assert.Equal(t, 4, len(fields), "should only have msg/time/level/context fields")
346 assert.Equal(t, "looks delicious", fields["msg"])
347 assert.Equal(t, "eating raw fish", fields["context"])
348
349 buffer.Reset()
350
351 llog.Warn("omg it is!")
352
353 err = json.Unmarshal(buffer.Bytes(), &fields)
354 require.NoError(t, err, "should have decoded second message")
355 assert.Equal(t, 4, len(fields), "should only have msg/time/level/context fields")
356 assert.Equal(t, "omg it is!", fields["msg"])
357 assert.Equal(t, "eating raw fish", fields["context"])
358 assert.Nil(t, fields["fields.msg"], "should not have prefixed previous `msg` entry")
359
360}
361
362func TestNestedLoggingReportsCorrectCaller(t *testing.T) {
363 var buffer bytes.Buffer

Callers

nothing calls this directly

Calls 6

NewFunction · 0.85
BytesMethod · 0.80
ResetMethod · 0.80
WithFieldMethod · 0.65
InfoMethod · 0.65
WarnMethod · 0.65

Tested by

no test coverage detected