Files
tendermint/libs/log/tracing_logger_test.go
Phil Salant bc572217c0 Fix linter errors thrown by lll (#3970)
* Fix long line errors in abci, crypto, and libs packages

* Fix long lines in p2p and rpc packages

* Fix long lines in abci, state, and tools packages

* Fix long lines in behaviour and blockchain packages

* Fix long lines in cmd and config packages

* Begin fixing long lines in consensus package

* Finish fixing long lines in consensus package

* Add lll exclusion for lines containing URLs

* Fix long lines in crypto package

* Fix long lines in evidence package

* Fix long lines in mempool and node packages

* Fix long lines in libs package

* Fix long lines in lite package

* Fix new long line in node package

* Fix long lines in p2p package

* Ignore gocritic warning

* Fix long lines in privval package

* Fix long lines in rpc package

* Fix long lines in scripts package

* Fix long lines in state package

* Fix long lines in tools package

* Fix long lines in types package

* Enable lll linter
2019-10-17 10:42:28 +02:00

65 lines
1.6 KiB
Go

package log_test
import (
"bytes"
stderr "errors"
"fmt"
"strings"
"testing"
"github.com/pkg/errors"
"github.com/tendermint/tendermint/libs/log"
)
func TestTracingLogger(t *testing.T) {
var buf bytes.Buffer
logger := log.NewTMJSONLogger(&buf)
logger1 := log.NewTracingLogger(logger)
err1 := errors.New("Courage is grace under pressure.")
err2 := errors.New("It does not matter how slowly you go, so long as you do not stop.")
logger1.With("err1", err1).Info("foo", "err2", err2)
want := strings.Replace(
strings.Replace(
`{"_msg":"foo","err1":"`+
fmt.Sprintf("%+v", err1)+
`","err2":"`+
fmt.Sprintf("%+v", err2)+
`","level":"info"}`,
"\t", "", -1,
), "\n", "", -1)
have := strings.Replace(strings.Replace(strings.TrimSpace(buf.String()), "\\n", "", -1), "\\t", "", -1)
if want != have {
t.Errorf("\nwant '%s'\nhave '%s'", want, have)
}
buf.Reset()
logger.With(
"err1", stderr.New("Opportunities don't happen. You create them."),
).Info(
"foo", "err2", stderr.New("Once you choose hope, anything's possible."),
)
want = `{"_msg":"foo",` +
`"err1":"Opportunities don't happen. You create them.",` +
`"err2":"Once you choose hope, anything's possible.",` +
`"level":"info"}`
have = strings.TrimSpace(buf.String())
if want != have {
t.Errorf("\nwant '%s'\nhave '%s'", want, have)
}
buf.Reset()
logger.With("user", "Sam").With("context", "value").Info("foo", "bar", "baz")
want = `{"_msg":"foo","bar":"baz","context":"value","level":"info","user":"Sam"}`
have = strings.TrimSpace(buf.String())
if want != have {
t.Errorf("\nwant '%s'\nhave '%s'", want, have)
}
}