From b0755c938ab9fe6f93a6b504e129deb9d390f048 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Sun, 28 Dec 2014 16:26:53 -0800 Subject: [PATCH] Better debug output --- Makefile | 13 +++++++++++++ account/signature.go | 5 +++++ binary/reflect.go | 19 +++++++++++-------- cmd/main.go | 2 +- mempool/log.go | 4 ---- p2p/connection.go | 1 + 6 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..29496756 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +all: build + +build: + go build -o tendermint github.com/tendermint/tendermint/cmd + +test: + go test github.com/tendermint/tendermint/... + +list_deps: + go list -f '{{join .Deps "\n"}}' github.com/tendermint/tendermint/... | xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}' + +get_deps: + go get github.com/tendermint/tendermint/... diff --git a/account/signature.go b/account/signature.go index 7b9d6b5f..691b6d68 100644 --- a/account/signature.go +++ b/account/signature.go @@ -2,6 +2,7 @@ package account import ( "errors" + "fmt" "io" "reflect" @@ -56,3 +57,7 @@ func (sig SignatureEd25519) ValidateBasic() error { func (sig SignatureEd25519) IsZero() bool { return len(sig.Bytes) == 0 } + +func (sig SignatureEd25519) String() string { + return fmt.Sprintf("%X", Fingerprint(sig.Bytes)) +} diff --git a/binary/reflect.go b/binary/reflect.go index 1bf28245..fda0fc49 100644 --- a/binary/reflect.go +++ b/binary/reflect.go @@ -189,13 +189,8 @@ func writeReflect(rv reflect.Value, rt reflect.Type, w io.Writer, n *int64, err return } - // Dereference pointer or interface - if rt.Kind() == reflect.Ptr { - rt = rt.Elem() - rv = rv.Elem() - // RegisterType registers the ptr type, - // so typeInfo is already for the ptr. - } else if rt.Kind() == reflect.Interface { + // Dereference interface + if rt.Kind() == reflect.Interface { rv = rv.Elem() rt = rv.Type() typeInfo = typeInfos[rt] @@ -205,6 +200,14 @@ func writeReflect(rv reflect.Value, rt reflect.Type, w io.Writer, n *int64, err } } + // Dereference pointer + if rt.Kind() == reflect.Ptr { + rt = rt.Elem() + rv = rv.Elem() + // RegisterType registers the ptr type, + // so typeInfo is already for the ptr. + } + // Write TypeByte prefix if typeInfo.HasTypeByte { WriteByte(typeInfo.TypeByte, w, n, err) @@ -215,7 +218,7 @@ func writeReflect(rv reflect.Value, rt reflect.Type, w io.Writer, n *int64, err elemRt := rt.Elem() if elemRt.Kind() == reflect.Uint8 { // Special case: Byteslices - byteslice := rv.Interface().([]byte) + byteslice := rv.Bytes() WriteByteSlice(byteslice, w, n, err) } else { // Write length diff --git a/cmd/main.go b/cmd/main.go index 35a8446d..8cb9ed0e 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -33,6 +33,6 @@ Commands: case "probe_upnp": probe_upnp() default: - fmt.Println("Unknown command %v", args[0]) + fmt.Printf("Unknown command %v\n", args[0]) } } diff --git a/mempool/log.go b/mempool/log.go index 8e2775f9..dabc294f 100644 --- a/mempool/log.go +++ b/mempool/log.go @@ -6,10 +6,6 @@ import ( var log = logging.MustGetLogger("mempool") -func init() { - logging.SetFormatter(logging.MustStringFormatter("[%{level:.1s}] %{message}")) -} - func SetMempoolLogger(l *logging.Logger) { log = l } diff --git a/p2p/connection.go b/p2p/connection.go index 607f9120..58ea6857 100644 --- a/p2p/connection.go +++ b/p2p/connection.go @@ -183,6 +183,7 @@ func (c *MConnection) Send(chId byte, msg interface{}) bool { } log.Debug("[%X] Send to %v: %v", chId, c, msg) + log.Debug(" Bytes: %X", BinaryBytes(msg)) // Send message to channel. channel, ok := c.channelsIdx[chId]