Skip to content
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

Merged
merged 4 commits into from
Sep 24, 2018
Merged

Some key-value is missing in the log #190

merged 4 commits into from
Sep 24, 2018

Conversation

cshuaimin
Copy link
Contributor

handlers.go line 301:

lm := make(lgbl.DeferredMap)
lm["peer"] = func() interface{} { return p.Pretty() }
eip := log.EventBegin(ctx, "handleGetProviders", lm)
defer eip.Done()
// ...
lm["key"] = func() interface{} { return c.String() }

The last line does not work and the key does not appear in the log message. And I see that the EventBegin has been deprecated, so I changed all EventBegin to Start.

Copy link
Member

@Stebalien Stebalien left a 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())
Copy link
Member

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).

  1. LogKV is more for events/log items. SetTag will set the "peer" property for the event.
  2. Pretty will convert to base58 (slow).

Copy link
Contributor Author

@cshuaimin cshuaimin Aug 24, 2018

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?

Copy link
Member

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().

Copy link
Member

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)
Copy link
Member

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:

  1. 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.
  2. Use defer func() { log.FinishWithErr(ctx, _err) }

But that's up to you.

Copy link
Contributor Author

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.
@dokterbob
Copy link

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! :)

@Stebalien
Copy link
Member

Not quite. We need to actually update go-log.

@Stebalien Stebalien merged commit fd8d798 into libp2p:master Sep 24, 2018
@dokterbob
Copy link

Thanks! Now let's hope it makes it into IPFS soon. ^^

@Stebalien
Copy link
Member

This one's pretty easy to update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants