k3s/vendor/github.com/canonical/go-dqlite/internal/logging/func.go
2019-11-10 04:05:59 +00:00

27 lines
644 B
Go

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...)
}
}