9 "github.com/go-kit/kit/log"
10 "github.com/go-logfmt/logfmt"
13 func TestLogfmtLogger(t *testing.T) {
15 buf := &bytes.Buffer{}
16 logger := log.NewLogfmtLogger(buf)
18 if err := logger.Log("hello", "world"); err != nil {
21 if want, have := "hello=world\n", buf.String(); want != have {
22 t.Errorf("want %#v, have %#v", want, have)
26 if err := logger.Log("a", 1, "err", errors.New("error")); err != nil {
29 if want, have := "a=1 err=error\n", buf.String(); want != have {
30 t.Errorf("want %#v, have %#v", want, have)
34 if err := logger.Log("std_map", map[int]int{1: 2}, "my_map", mymap{0: 0}); err != nil {
37 if want, have := "std_map=\""+logfmt.ErrUnsupportedValueType.Error()+"\" my_map=special_behavior\n", buf.String(); want != have {
38 t.Errorf("want %#v, have %#v", want, have)
42 func BenchmarkLogfmtLoggerSimple(b *testing.B) {
43 benchmarkRunner(b, log.NewLogfmtLogger(ioutil.Discard), baseMessage)
46 func BenchmarkLogfmtLoggerContextual(b *testing.B) {
47 benchmarkRunner(b, log.NewLogfmtLogger(ioutil.Discard), withMessage)
50 func TestLogfmtLoggerConcurrency(t *testing.T) {
52 testConcurrency(t, log.NewLogfmtLogger(ioutil.Discard), 10000)
55 type mymap map[int]int
57 func (m mymap) String() string { return "special_behavior" }