File: func.go

package info (click to toggle)
golang-github-canonical-go-dqlite 2.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 720 kB
  • sloc: sh: 380; makefile: 5
file content (26 lines) | stat: -rw-r--r-- 644 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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...)
	}
}