-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some key-value is missing in the log #190
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
handlers.go
Outdated
defer log.EventBegin(ctx, "handleFindPeer", p).Done() | ||
ctx = log.Start(ctx, "handleFindPeer") | ||
defer log.Finish(ctx) | ||
log.LogKV(ctx, "peer", p.Pretty()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be log.SetTag(ctx, "peer", p)
.
LogKV
is more for events/log items.SetTag
will set the "peer" property for the event.Pretty
will convert to base58 (slow).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know lots of base58 encoding is too slow, but without this, the output will be:
{<...>, "Tags":{"peer":"\u0012 =\ufffd\ufffd\ufffd\n\ufffds}\ufffdGpnc0\ufffd\ufffd\ufffdhc\ufffd,}\ufffd\"\ufffd\u000c\ufffd\u0000ږ\ufffd\u0005","system":"dht"},"Logs":[{"Timestamp":"2018-08-24T10:51:23.56479413+08:00","Fields":[{"Key":"key","Value":"QmVYL1EPRThV5pg2Vybz2kxuCzyUcmvvRZXToQqs4aSxBn"}]}]}
Should we use Pretty
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks like a bug. Our logger should be calling String()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed here: ipfs/go-log#45.
handlers.go
Outdated
@@ -249,7 +250,9 @@ func (dht *IpfsDHT) handlePing(_ context.Context, p peer.ID, pmes *pb.Message) ( | |||
} | |||
|
|||
func (dht *IpfsDHT) handleFindPeer(ctx context.Context, p peer.ID, pmes *pb.Message) (*pb.Message, error) { | |||
defer log.EventBegin(ctx, "handleFindPeer", p).Done() | |||
ctx = log.Start(ctx, "handleFindPeer") | |||
defer log.Finish(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can actually skip the SetErr
now and:
- Set a named error return value (e.g.,
_err
). This'll "capture" the err return value in a variable and make it accessible from deferred functions. - Use
defer func() { log.FinishWithErr(ctx, _err) }
But that's up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So clever way! Thanks for your idea.
…er ID. 2. Switch `LogKV()` to `SetTag`. 3. Use a smarter way to log errors.
Hey, this one looks ready for merge to me. Note that this is a fix allowing the currently broken sniffer for ipfs-search to function again - so I can upgrade IPFS to 0.4.17, finally! :) |
Not quite. We need to actually update go-log. |
Thanks! Now let's hope it makes it into IPFS soon. ^^ |
This one's pretty easy to update. |
handlers.go line 301:
The last line does not work and the
key
does not appear in the log message. And I see that theEventBegin
has been deprecated, so I changed allEventBegin
toStart
.