10 "github.com/pkg/errors"
11 "github.com/tendermint/tmlibs/log"
14 func TestTracingLogger(t *testing.T) {
17 logger := log.NewTMJSONLogger(&buf)
19 logger1 := log.NewTracingLogger(logger)
20 err1 := errors.New("Courage is grace under pressure.")
21 err2 := errors.New("It does not matter how slowly you go, so long as you do not stop.")
22 logger1.With("err1", err1).Info("foo", "err2", err2)
23 have := strings.Replace(strings.Replace(strings.TrimSpace(buf.String()), "\\n", "", -1), "\\t", "", -1)
24 if want := strings.Replace(strings.Replace(`{"_msg":"foo","err1":"`+fmt.Sprintf("%+v", err1)+`","err2":"`+fmt.Sprintf("%+v", err2)+`","level":"info"}`, "\t", "", -1), "\n", "", -1); want != have {
25 t.Errorf("\nwant '%s'\nhave '%s'", want, have)
30 logger.With("err1", stderr.New("Opportunities don't happen. You create them.")).Info("foo", "err2", stderr.New("Once you choose hope, anything's possible."))
31 if want, have := `{"_msg":"foo","err1":"Opportunities don't happen. You create them.","err2":"Once you choose hope, anything's possible.","level":"info"}`, strings.TrimSpace(buf.String()); want != have {
32 t.Errorf("\nwant '%s'\nhave '%s'", want, have)
37 logger.With("user", "Sam").With("context", "value").Info("foo", "bar", "baz")
38 if want, have := `{"_msg":"foo","bar":"baz","context":"value","level":"info","user":"Sam"}`, strings.TrimSpace(buf.String()); want != have {
39 t.Errorf("\nwant '%s'\nhave '%s'", want, have)