From ff9720c9052c1d9acb91b9a035be3767c5473e16 Mon Sep 17 00:00:00 2001 From: Tomas Virgl Date: Thu, 27 Jul 2017 13:24:08 +0200 Subject: [PATCH 1/2] Fix logging of keys. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently keys that get logged are casted from []byte. Which means that log output looks like this. ``` {"event":"getClosestPeersBegin","key":"\u0012 \ufffdᱡ\ufffd`\ufffdF]\ufffd\ufffdᠸCƶ\u0006E\ufffdrb\ufffd\ufffdO\ufffd\ufffdu\ufffd\ufffdj\u000b","system":"dht","time":"2017-07-27T11:12:08.51775836Z"} ``` after fix like this: ``` {"event":"getClosestPeersBegin","key":"QmQyyaB8znrakGydP3ynRsXre96Uw9wc6w6zuP61bbZuNj","system":"dht","time":"2017-07-27T11:16:30.693008112Z"} ``` --- lookup.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lookup.go b/lookup.go index a1db322dd37..4029f5e3a96 100644 --- a/lookup.go +++ b/lookup.go @@ -3,6 +3,7 @@ package dht import ( "context" + cid "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log" kb "github.com/libp2p/go-libp2p-kbucket" peer "github.com/libp2p/go-libp2p-peer" @@ -29,6 +30,9 @@ func toPeerInfos(ps []peer.ID) []*pstore.PeerInfo { } func loggableKey(k string) logging.LoggableMap { + if cid, err := cid.Cast([]byte(k)); err == nil { + k = cid.String() + } return logging.LoggableMap{ "key": k, } From 3a8cbdef5575576477160bf5f80b62ff0a54182f Mon Sep 17 00:00:00 2001 From: Tomas Virgl Date: Thu, 27 Jul 2017 16:49:44 +0200 Subject: [PATCH 2/2] Update lookup.go --- lookup.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lookup.go b/lookup.go index 4029f5e3a96..9a4285d92c6 100644 --- a/lookup.go +++ b/lookup.go @@ -30,7 +30,10 @@ func toPeerInfos(ps []peer.ID) []*pstore.PeerInfo { } func loggableKey(k string) logging.LoggableMap { - if cid, err := cid.Cast([]byte(k)); err == nil { + cid, err := cid.Cast([]byte(k)) + if err != nil { + log.Errorf("loggableKey could not cast key: %v", err) + } else { k = cid.String() } return logging.LoggableMap{