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

Function TestTimeOverrideMultipleLogs

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

Source from the content-addressed store, hash-verified

301}
302
303func TestTimeOverrideMultipleLogs(t *testing.T) {
304 var buffer bytes.Buffer
305 var firstFields, secondFields Fields
306
307 logger := New()
308 logger.Out = &buffer
309 formatter := new(JSONFormatter)
310 formatter.TimestampFormat = time.StampMilli
311 logger.Formatter = formatter
312
313 llog := logger.WithField("herp", "derp")
314 llog.Info("foo")
315
316 err := json.Unmarshal(buffer.Bytes(), &firstFields)
317 require.NoError(t, err, "should have decoded first message")
318
319 buffer.Reset()
320
321 time.Sleep(10 * time.Millisecond)
322 llog.Info("bar")
323
324 err = json.Unmarshal(buffer.Bytes(), &secondFields)
325 require.NoError(t, err, "should have decoded second message")
326
327 assert.NotEqual(t, firstFields["time"], secondFields["time"], "timestamps should not be equal")
328}
329
330func TestDoubleLoggingDoesntPrefixPreviousFields(t *testing.T) {
331

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected