From 17a26daa87ddf41114fd70068fb14c1b1ed542b6 Mon Sep 17 00:00:00 2001 From: YACOVM Date: Wed, 3 May 2017 11:13:32 +0300 Subject: [PATCH] [FAB-3445] unrecognized characters in the gossip log MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- gossip/gossip/chanstate.go | 5 ----- gossip/util/logging.go | 4 +++- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/gossip/gossip/chanstate.go b/gossip/gossip/chanstate.go index d0c112a97bb..8f7f528508a 100644 --- a/gossip/gossip/chanstate.go +++ b/gossip/gossip/chanstate.go @@ -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" ) @@ -37,10 +36,6 @@ type channelState struct { g *gossipServiceImpl } -func init() { - util.SetupTestLogging() -} - func (cs *channelState) stop() { if cs.isStopping() { return diff --git a/gossip/util/logging.go b/gossip/util/logging.go index a908247d743..8c8ecc3acff 100644 --- a/gossip/util/logging.go +++ b/gossip/util/logging.go @@ -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 } @@ -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) }