traefik/pkg/logs/haystack_test.go

25 lines
550 B
Go
Raw Normal View History

2022-11-21 17:36:05 +00:00
package logs
import (
2022-11-23 11:14:04 +00:00
"bytes"
2022-11-21 17:36:05 +00:00
"os"
"testing"
"time"
"github.com/rs/zerolog"
2022-11-23 11:14:04 +00:00
"github.com/stretchr/testify/assert"
2022-11-21 17:36:05 +00:00
)
func TestNewHaystackLogger(t *testing.T) {
2022-11-23 11:14:04 +00:00
buf := bytes.NewBuffer(nil)
cwb := zerolog.ConsoleWriter{Out: buf, TimeFormat: time.RFC3339, NoColor: true}
out := zerolog.MultiLevelWriter(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}, cwb)
2022-11-21 17:36:05 +00:00
logger := NewHaystackLogger(zerolog.New(out).With().Caller().Logger())
logger.Info("foo")
2022-11-23 11:14:04 +00:00
assert.Equal(t, "<nil> INF haystack_test.go:21 > foo\n", buf.String())
2022-11-21 17:36:05 +00:00
}