k3s/vendor/github.com/canonical/go-dqlite/internal/logging/func.go

27 lines
644 B
Go
Raw Normal View History

2019-11-08 21:45:10 +00:00
package logging
import (
"fmt"
"testing"
)
// Func is a function that can be used for logging.
type Func func(Level, string, ...interface{})
// Test returns a logging function that forwards messages to the test logger.
func Test(t *testing.T) Func {
return func(l Level, format string, a ...interface{}) {
format = fmt.Sprintf("%s: %s", l.String(), format)
t.Logf(format, a...)
}
}
// Stdout returns a logging function that prints log messages on standard
// output.
func Stdout() Func {
return func(l Level, format string, a ...interface{}) {
format = fmt.Sprintf("%s: %s\n", l.String(), format)
fmt.Printf(format, a...)
}
}