github.com/grafana/pyroscope@v1.18.0/pkg/test/logger.go (about) 1 // SPDX-License-Identifier: AGPL-3.0-only 2 3 package test 4 5 import ( 6 "bytes" 7 "testing" 8 9 "github.com/go-kit/log" 10 ) 11 12 type TestingLogger struct { 13 t testing.TB 14 } 15 16 func NewTestingLogger(t testing.TB) *TestingLogger { 17 return &TestingLogger{t: t} 18 } 19 20 func (l *TestingLogger) Log(keyvals ...interface{}) error { 21 l.t.Helper() 22 buf := bytes.NewBuffer(nil) 23 lf := log.NewLogfmtLogger(buf) 24 lf.Log(keyvals...) 25 bs := buf.Bytes() 26 if len(bs) > 0 && bs[len(bs)-1] == '\n' { 27 bs = bs[:len(bs)-1] 28 } 29 l.t.Log(string(bs)) 30 return nil 31 }