package util
import (
"os"
"testing"
"time"
"github.com/go-kit/log"
"github.com/grafana/agent/pkg/flow/logging"
"github.com/stretchr/testify/require"
)
func TestLogger(t *testing.T) log.Logger {
t.Helper()
l := log.NewSyncLogger(log.NewLogfmtLogger(os.Stderr))
l = log.WithPrefix(l,
"test", t.Name(),
"ts", log.Valuer(testTimestamp),
)
return l
}
func TestFlowLogger(t require.TestingT) *logging.Logger {
if t, ok := t.(*testing.T); ok {
t.Helper()
}
sink, err := logging.WriterSink(os.Stderr, logging.SinkOptions{
Level: logging.LevelDebug,
Format: logging.FormatLogfmt,
})
require.NoError(t, err)
return logging.New(sink)
}
func testTimestamp() interface{} {
t := time.Now().UTC()
return t.Format("15:04:05.000")
}