Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
refactor: adjust log levels
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkmc committed Mar 16, 2020
1 parent ddf64ae commit cee7d2d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/libp2p/go-libp2p-testing v0.1.1
github.com/libp2p/go-msgio v0.0.4
github.com/multiformats/go-multiaddr v0.2.1
gopkg.in/src-d/go-log.v1 v1.0.1
go.uber.org/zap v1.10.0
)

go 1.12
7 changes: 7 additions & 0 deletions internal/messagequeue/messagequeue.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import (
logging "github.com/ipfs/go-log"
peer "github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p/p2p/protocol/ping"
"go.uber.org/zap"
)

var log = logging.Logger("bitswap")
var sflog = log.Desugar()

const (
defaultRebroadcastInterval = 30 * time.Second
Expand Down Expand Up @@ -452,6 +454,11 @@ func (mq *MessageQueue) simulateDontHaveWithTimeout(msg bsmsg.BitSwapMessage) {
}

func (mq *MessageQueue) logOutgoingMessage(msg bsmsg.BitSwapMessage) {
// Save some CPU cycles and allocations if log level is higher than debug
if ce := sflog.Check(zap.DebugLevel, "Bitswap -> send wants"); ce == nil {
return
}

self := mq.network.Self()
entries := msg.Wantlist()
for _, e := range entries {
Expand Down
11 changes: 8 additions & 3 deletions internal/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import (
logging "github.com/ipfs/go-log"
peer "github.com/libp2p/go-libp2p-core/peer"
loggables "github.com/libp2p/go-libp2p-loggables"
"go.uber.org/zap"
)

var log = logging.Logger("bs:sess")
var sflog = log.Desugar()

const (
broadcastLiveWantsLimit = 64
Expand Down Expand Up @@ -194,8 +196,11 @@ func (s *Session) ReceiveFrom(from peer.ID, ks []cid.Cid, haves []cid.Cid, dontH
}

func (s *Session) logReceiveFrom(from peer.ID, interestedKs []cid.Cid, haves []cid.Cid, dontHaves []cid.Cid) {
// log.Debugf("Ses%d<-%s: %d blocks, %d haves, %d dont haves\n",
// s.id, from, len(interestedKs), len(wantedHaves), len(wantedDontHaves))
// Save some CPU cycles if log level is higher than debug
if ce := sflog.Check(zap.DebugLevel, "Bitswap <- rcv message"); ce == nil {
return
}

for _, c := range interestedKs {
log.Debugw("Bitswap <- block", "local", s.self, "from", from, "cid", c, "session", s.id)
}
Expand Down Expand Up @@ -336,7 +341,7 @@ func (s *Session) broadcastWantHaves(ctx context.Context, wants []cid.Cid) {
// Search for providers who have the first want in the list.
// Typically if the provider has the first block they will have
// the rest of the blocks also.
log.Infof("Ses%d: FindMorePeers with want %s (1st of %d wants)", s.id, wants[0], len(wants))
log.Debugf("Ses%d: FindMorePeers with want %s (1st of %d wants)", s.id, wants[0], len(wants))
s.findMorePeers(ctx, wants[0])
}
s.resetIdleTick()
Expand Down
6 changes: 4 additions & 2 deletions internal/wantmanager/wantmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import (
bssim "github.com/ipfs/go-bitswap/internal/sessioninterestmanager"
"github.com/ipfs/go-bitswap/internal/sessionmanager"
bsswl "github.com/ipfs/go-bitswap/internal/sessionwantlist"
"gopkg.in/src-d/go-log.v1"
logging "github.com/ipfs/go-log"

cid "github.com/ipfs/go-cid"
peer "github.com/libp2p/go-libp2p-core/peer"
)

var log = logging.Logger("bitswap")

// PeerHandler sends wants / cancels to other peers
type PeerHandler interface {
// Connected is called when a peer connects, with any initial want-haves
Expand Down Expand Up @@ -76,7 +78,7 @@ func (wm *WantManager) ReceiveFrom(ctx context.Context, p peer.ID, blks []cid.Ci
// BroadcastWantHaves is called when want-haves should be broadcast to all
// connected peers (as part of session discovery)
func (wm *WantManager) BroadcastWantHaves(ctx context.Context, ses uint64, wantHaves []cid.Cid) {
log.Infof("BroadcastWantHaves session%d: %s", ses, wantHaves)
log.Debugf("BroadcastWantHaves session%d: %s", ses, wantHaves)

// Record broadcast wants
wm.bcwl.Add(wantHaves, ses)
Expand Down

0 comments on commit cee7d2d

Please sign in to comment.