Skip to content

Commit

Permalink
[FAB-3445] unrecognized characters in the gossip log
Browse files Browse the repository at this point in the history
Some of our modules print funny characters such as:
2017-04-27 08:21:33.648 UTC [flogging] setModuleLevel -> DEBU 2eea Module 'gossip/gossip#^>+�>�Q�
�N�5�W"���?�xʷ��?J

This is caused because we have (for testing) module names that consist
of both the module itself + a descriptor for the peer instance, since
all instances run in the same process in unit tests.

In some modules the descriptor is the PKI-ID of the peer, which
in tests its simply the endpoint of the peer, but in production
this is the hash of the cert --> which isn't ASCII.

I adjusted our logging config to use only the module in production,
and use the existing flow only in test code, where it belongs.

Change-Id: Idc3ec6a4b9223d1506873a3af7210bf1271654f2
Signed-off-by: Yacov Manevich <yacovm@il.ibm.com>
  • Loading branch information
yacovm committed May 3, 2017
1 parent eff8380 commit 17a26da
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
5 changes: 0 additions & 5 deletions gossip/gossip/chanstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/hyperledger/fabric/gossip/common"
"github.com/hyperledger/fabric/gossip/discovery"
"github.com/hyperledger/fabric/gossip/gossip/channel"
"github.com/hyperledger/fabric/gossip/util"
proto "github.com/hyperledger/fabric/protos/gossip"
)

Expand All @@ -37,10 +36,6 @@ type channelState struct {
g *gossipServiceImpl
}

func init() {
util.SetupTestLogging()
}

func (cs *channelState) stop() {
if cs.isStopping() {
return
Expand Down
4 changes: 3 additions & 1 deletion gossip/util/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ const (

var loggersByModules = make(map[string]*logging.Logger)
var lock = sync.Mutex{}
var testMode bool

// defaultTestSpec is the default logging level for gossip tests
var defaultTestSpec = "WARNING"

// GetLogger returns a logger for given gossip module and peerID
func GetLogger(module string, peerID string) *logging.Logger {
if peerID != "" {
if peerID != "" && testMode {
module = module + "#" + peerID
}

Expand All @@ -63,5 +64,6 @@ func GetLogger(module string, peerID string) *logging.Logger {

// SetupTestLogging sets the default log levels for gossip unit tests
func SetupTestLogging() {
testMode = true
flogging.InitFromSpec(defaultTestSpec)
}

0 comments on commit 17a26da

Please sign in to comment.