func TestMultiLogger_Log(t *testing.T) {
	b1 := bytes.NewBuffer(nil)
	b2 := bytes.NewBuffer(nil)

	l1 := log.NewJSONLogger(b1)
	l2 := log.NewJSONLogger(b2)

	l := sklog.NewMultiLogger(l1, l2)

	sklog.Debug(l, "debug message")
	sklog.Info(l, "info message")
	sklog.Error(l, errors.New("sklog_test: example error message"))

	assert.Equal(t, b1.String(), b2.String())

	b1.Reset()
	b2.Reset()

	l1 = &faultyLogger{}
	l2 = log.NewJSONLogger(b2)

	l = sklog.NewMultiLogger(l1, l2)

	sklog.Debug(l, "debug message")
	sklog.Info(l, "info message")
	sklog.Error(l, errors.New("sklog_test: example error message"))

	assert.Contains(t, b2.String(), "debug message")
	assert.Contains(t, b2.String(), "msg")
	assert.Contains(t, b2.String(), "info message")
	assert.Contains(t, b2.String(), "info")
	assert.Contains(t, b2.String(), "debug")
	assert.Contains(t, b2.String(), "sklog_test: example error message")

}
Example #2
0
func testErrorWithOnlyMessage(t *testing.T, b *bytes.Buffer, l log.Logger) {
	err := errors.New("sklog_test: example error")
	sklog.Error(l, err)

	assert.Contains(t, b.String(), `"level":"error"`)
	assert.Contains(t, b.String(), `"msg":"`+err.Error()+`"`)
	assert.Contains(t, b.String(), `"timestamp":`)
}
Example #3
0
func TestNewContextErrorGeneric(t *testing.T) {
	sklog.SetContextErrorFunc(ctxpq.NewContextErrorGeneric)

	b := bytes.NewBuffer(nil)
	l := log.NewJSONLogger(b)

	for _, e := range pqErrors {
		sklog.Error(l, e)

		assertPqError(t, b, e)
		b.Reset()
	}

	for _, e := range genericErrors {
		sklog.Error(l, e)

		assertGenericError(t, b, e)
		b.Reset()
	}
}