traefik/pkg/logs/logrus_test.go

25 lines
552 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 TestNewLogrusStdWrapper(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 := NewLogrusWrapper(zerolog.New(out).With().Caller().Logger())
logger.Println("foo")
2022-11-23 11:14:04 +00:00
assert.Equal(t, "<nil> DBG logrus_test.go:21 > foo\n", buf.String())
2022-11-21 17:36:05 +00:00
}