types/logger: add TestLogger

We have this in another repo and I wanted it here too.

Updates #cleanup

Change-Id: If93dc73f11eaaada5024acf2a885a153b88db5a0
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/9181/head
Brad Fitzpatrick 1 year ago committed by Brad Fitzpatrick
parent 77060c4d89
commit ecc1d6907b

@ -373,3 +373,19 @@ func (a asJSONResult) Format(s fmt.State, verb rune) {
} }
s.Write(v) s.Write(v)
} }
// TBLogger is the testing.TB subset needed by TestLogger.
type TBLogger interface {
Helper()
Logf(format string, args ...any)
}
// TestLogger returns a logger that logs to tb.Logf
// with a prefix to make it easier to distinguish spam
// from explicit test failures.
func TestLogger(tb TBLogger) Logf {
return func(format string, args ...any) {
tb.Helper()
tb.Logf(" ... "+format, args...)
}
}

Loading…
Cancel
Save