Skip to content

Commit 6271740

Browse files
committed
[FAB-1217] Integrate flogging with gossip logging
Integrate the flogging package with gossip logging, making the gossip logging control consistent with the logging control methods of the core fabric modules. - Support all the control methods described in the logging control document when gossip is in a peer process, see: https://hyperledger-fabric.readthedocs.io/en/latest/Setup/logging-control/ For example, if the gossip modules is called by `peer node start`, the gossip logging level can be overridden in these ways listed below, from strongest to weakest: 1. The --logging-level=<level> command line option. 2. The CORE_LOGGING_LEVEL env variable. 3. The CORE_LOGGING_NODE env variable. 4. The "logging.node" spec defined in the peer/core.yaml file. And a command like: peer logging setlevel <module> <log level> [flags] can set logging level for a specified module on the fly. - Fallback to gossip's default logging level and format when gossip is not in a peer process. The current default logging level is set to "WARNING", and the default logging format is taken from the flogging package. Resolves FAB-1217. Change-Id: I57e0d5ca4dc10a4774e3ac20e2e71e6ff85e18b8 Signed-off-by: Xiaoyi Wang <[email protected]> Signed-off-by: Ray Chen <[email protected]>
1 parent bdba196 commit 6271740

16 files changed

+60
-101
lines changed

gossip/comm/comm_impl.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ func NewCommInstanceWithServer(port int, idMapper identity.Mapper, peerIdentity
113113
proto.RegisterGossipServer(s, commInst)
114114
}
115115

116-
commInst.logger.SetLevel(logging.WARNING)
117-
118116
return commInst, nil
119117
}
120118

@@ -143,7 +141,7 @@ type commImpl struct {
143141
selfCertHash []byte
144142
peerIdentity api.PeerIdentityType
145143
idMapper identity.Mapper
146-
logger *util.Logger
144+
logger *logging.Logger
147145
opts []grpc.DialOption
148146
connStore *connectionStore
149147
PKIID []byte

gossip/comm/conn.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323

2424
"github.com/hyperledger/fabric/gossip/common"
2525
"github.com/hyperledger/fabric/gossip/proto"
26-
"github.com/hyperledger/fabric/gossip/util"
26+
"github.com/op/go-logging"
2727
"google.golang.org/grpc"
2828
)
2929

@@ -34,7 +34,7 @@ type connFactory interface {
3434
}
3535

3636
type connectionStore struct {
37-
logger *util.Logger // logger
37+
logger *logging.Logger // logger
3838
isClosing bool // whether this connection store is shutting down
3939
connFactory connFactory // creates a connection to remote peer
4040
sync.RWMutex // synchronize access to shared variables
@@ -43,7 +43,7 @@ type connectionStore struct {
4343
// used to prevent concurrent connection establishment to the same remote endpoint
4444
}
4545

46-
func newConnStore(connFactory connFactory, logger *util.Logger) *connectionStore {
46+
func newConnStore(connFactory connFactory, logger *logging.Logger) *connectionStore {
4747
return &connectionStore{
4848
connFactory: connFactory,
4949
isClosing: false,
@@ -197,7 +197,7 @@ func newConnection(cl proto.GossipClient, c *grpc.ClientConn, cs proto.Gossip_Go
197197

198198
type connection struct {
199199
outBuff chan *msgSending
200-
logger *util.Logger // logger
200+
logger *logging.Logger // logger
201201
pkiID common.PKIidType // pkiID of the remote endpoint
202202
handler handler // function to invoke upon a message reception
203203
conn *grpc.ClientConn // gRPC connection to remote endpoint

gossip/comm/mock/mock_comm.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"github.com/hyperledger/fabric/gossip/comm"
2121
"github.com/hyperledger/fabric/gossip/common"
2222
"github.com/hyperledger/fabric/gossip/proto"
23-
"github.com/op/go-logging"
23+
"github.com/hyperledger/fabric/gossip/util"
2424
)
2525

2626
// Mock which aims to simulate socket
@@ -61,12 +61,7 @@ type commMock struct {
6161
done chan struct{}
6262
}
6363

64-
var logger *logging.Logger // package-level logger
65-
66-
func init() {
67-
logger = logging.MustGetLogger("mockComm")
68-
logging.SetLevel(logging.DEBUG, logger.Module)
69-
}
64+
var logger = util.GetLogger(util.LoggingMockModule, "")
7065

7166
// NewCommMock creates mocked communication object
7267
func NewCommMock(id string, members map[string]*socketMock) comm.Comm {

gossip/discovery/discovery_impl.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ type gossipDiscoveryImpl struct {
9191

9292
toDieChan chan struct{}
9393
toDieFlag int32
94-
logger *util.Logger
94+
logger *logging.Logger
9595
}
9696

9797
// NewDiscoveryService returns a new discovery service with the comm module passed and the crypto service passed
@@ -118,8 +118,6 @@ func NewDiscoveryService(bootstrapPeers []string, self NetworkMember, comm CommS
118118
logger: util.GetLogger(util.LoggingDiscoveryModule, self.Endpoint),
119119
}
120120

121-
d.logger.SetLevel(logging.WARNING)
122-
123121
go d.periodicalSendAlive()
124122
go d.periodicalCheckAlive()
125123
go d.handleMessages()

gossip/discovery/discovery_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727

2828
"github.com/hyperledger/fabric/gossip/common"
2929
"github.com/hyperledger/fabric/gossip/proto"
30-
"github.com/op/go-logging"
3130
"github.com/stretchr/testify/assert"
3231
"golang.org/x/net/context"
3332
"google.golang.org/grpc"
@@ -245,7 +244,6 @@ func createDiscoveryInstanceThatGossips(port int, id string, bootstrapPeers []st
245244
s := grpc.NewServer()
246245

247246
discSvc := NewDiscoveryService(bootstrapPeers, self, comm, comm)
248-
discSvc.(*gossipDiscoveryImpl).logger.SetLevel(logging.WARNING)
249247
gossInst := &gossipInstance{comm: comm, gRGCserv: s, Discovery: discSvc, lsnr: ll, shouldGossip: shouldGossip}
250248

251249
proto.RegisterGossipServer(s, gossInst)

gossip/election/election.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,14 @@ func NewLeaderElectionService(adapter LeaderElectionAdapter, id string, callback
143143
adapter: adapter,
144144
stopChan: make(chan struct{}, 1),
145145
interruptChan: make(chan struct{}, 1),
146-
logger: logging.MustGetLogger("LeaderElection"),
146+
logger: util.GetLogger(util.LoggingElectionModule, ""),
147147
callback: noopCallback,
148148
}
149149

150150
if callback != nil {
151151
le.callback = callback
152152
}
153153

154-
// TODO: This will be configured using the core.yaml when FAB-1217 (Integrate peer logging with gossip logging) is done
155-
logging.SetLevel(logging.WARNING, "LeaderElection")
156154
go le.start()
157155
return le
158156
}

gossip/gossip/certstore.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/hyperledger/fabric/gossip/identity"
2929
"github.com/hyperledger/fabric/gossip/proto"
3030
"github.com/hyperledger/fabric/gossip/util"
31+
"github.com/op/go-logging"
3132
)
3233

3334
// certStore supports pull dissemination of identity messages
@@ -36,13 +37,13 @@ type certStore struct {
3637
selfIdentity api.PeerIdentityType
3738
idMapper identity.Mapper
3839
pull pull.Mediator
39-
logger *util.Logger
40+
logger *logging.Logger
4041
mcs api.MessageCryptoService
4142
}
4243

4344
func newCertStore(puller pull.Mediator, idMapper identity.Mapper, selfIdentity api.PeerIdentityType, mcs api.MessageCryptoService) *certStore {
4445
selfPKIID := idMapper.GetPKIidOfCert(selfIdentity)
45-
logger := util.GetLogger("certStore", string(selfPKIID))
46+
logger := util.GetLogger(util.LoggingGossipModule, string(selfPKIID))
4647
if err := idMapper.Put(selfPKIID, selfIdentity); err != nil {
4748
logger.Error("Failed associating self PKIID to cert:", err)
4849
panic(fmt.Errorf("Failed associating self PKIID to cert: %v", err))
@@ -56,8 +57,6 @@ func newCertStore(puller pull.Mediator, idMapper identity.Mapper, selfIdentity a
5657
logger: logger,
5758
}
5859

59-
certStore.logger = util.GetLogger("certStore", string(selfPKIID))
60-
6160
if err := certStore.idMapper.Put(selfPKIID, selfIdentity); err != nil {
6261
certStore.logger.Panic("Failed associating self PKIID to cert:", err)
6362
}

gossip/gossip/channel/channel.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/hyperledger/fabric/gossip/gossip/pull"
3333
"github.com/hyperledger/fabric/gossip/proto"
3434
"github.com/hyperledger/fabric/gossip/util"
35+
"github.com/op/go-logging"
3536
)
3637

3738
// Config is a configuration item
@@ -122,7 +123,7 @@ type gossipChannel struct {
122123
leaderMsgStore msgstore.MessageStore
123124
chainID common.ChainID
124125
blocksPuller pull.Mediator
125-
logger *util.Logger
126+
logger *logging.Logger
126127
stateInfoPublishScheduler *time.Ticker
127128
stateInfoRequestScheduler *time.Ticker
128129
memFilter *membershipFilter
@@ -149,7 +150,7 @@ func NewGossipChannel(mcs api.MessageCryptoService, chainID common.ChainID, adap
149150
gc := &gossipChannel{
150151
mcs: mcs,
151152
Adapter: adapter,
152-
logger: util.GetLogger("channelState", adapter.GetConf().ID),
153+
logger: util.GetLogger(util.LoggingChannelModule, adapter.GetConf().ID),
153154
stopChan: make(chan struct{}, 1),
154155
shouldGossipStateInfo: int32(0),
155156
stateInfoPublishScheduler: time.NewTicker(adapter.GetConf().PublishStateInfoInterval),

gossip/gossip/chanstate.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
"github.com/hyperledger/fabric/gossip/gossip/msgstore"
3030
"github.com/hyperledger/fabric/gossip/gossip/pull"
3131
"github.com/hyperledger/fabric/gossip/proto"
32-
"github.com/hyperledger/fabric/gossip/util"
32+
"github.com/op/go-logging"
3333
)
3434

3535
type channelState struct {
@@ -159,7 +159,7 @@ type gossipChannel struct {
159159
stateInfoMsgStore msgstore.MessageStore
160160
chainID common.ChainID
161161
blocksPuller pull.Mediator
162-
logger *util.Logger
162+
logger *logging.Logger
163163
stateInfoPublishScheduler *time.Ticker
164164
stateInfoRequestScheduler *time.Ticker
165165
}

gossip/gossip/gossip_impl.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/hyperledger/fabric/gossip/identity"
3636
"github.com/hyperledger/fabric/gossip/proto"
3737
"github.com/hyperledger/fabric/gossip/util"
38+
"github.com/op/go-logging"
3839
"google.golang.org/grpc"
3940
)
4041

@@ -56,7 +57,7 @@ type gossipServiceImpl struct {
5657
incTime time.Time
5758
selfOrg api.OrgIdentityType
5859
*comm.ChannelDeMultiplexer
59-
logger *util.Logger
60+
logger *logging.Logger
6061
stopSignal *sync.WaitGroup
6162
conf *Config
6263
toDieChan chan struct{}
@@ -687,10 +688,10 @@ type discoverySecurityAdapter struct {
687688
idMapper identity.Mapper
688689
mcs api.MessageCryptoService
689690
c comm.Comm
690-
logger *util.Logger
691+
logger *logging.Logger
691692
}
692693

693-
func newDiscoverySecurityAdapter(idMapper identity.Mapper, mcs api.MessageCryptoService, c comm.Comm, logger *util.Logger) *discoverySecurityAdapter {
694+
func newDiscoverySecurityAdapter(idMapper identity.Mapper, mcs api.MessageCryptoService, c comm.Comm, logger *logging.Logger) *discoverySecurityAdapter {
694695
return &discoverySecurityAdapter{
695696
idMapper: idMapper,
696697
mcs: mcs,

gossip/gossip/pull/pullstore.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/hyperledger/fabric/gossip/gossip/algo"
2727
"github.com/hyperledger/fabric/gossip/proto"
2828
"github.com/hyperledger/fabric/gossip/util"
29+
"github.com/op/go-logging"
2930
)
3031

3132
const (
@@ -91,7 +92,7 @@ type pullMediatorImpl struct {
9192
idExtractor proto.IdentifierExtractor
9293
msgCons proto.MsgConsumer
9394
config PullConfig
94-
logger *util.Logger
95+
logger *logging.Logger
9596
sync.RWMutex
9697
itemId2msg map[string]*proto.GossipMessage
9798
Sender
@@ -105,7 +106,7 @@ func NewPullMediator(config PullConfig, sndr Sender, memSvc MembershipService, i
105106
msgType2Hook: make(map[PullMsgType][]MessageHook),
106107
idExtractor: idExtractor,
107108
config: config,
108-
logger: util.GetLogger("Pull", config.Id),
109+
logger: util.GetLogger(util.LoggingPullModule, config.Id),
109110
itemId2msg: make(map[string]*proto.GossipMessage),
110111
memBvc: memSvc,
111112
Sender: sndr,

gossip/service/gossip_service.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import (
2828
"github.com/hyperledger/fabric/gossip/integration"
2929
"github.com/hyperledger/fabric/gossip/proto"
3030
"github.com/hyperledger/fabric/gossip/state"
31+
"github.com/hyperledger/fabric/gossip/util"
3132
"github.com/hyperledger/fabric/protos/common"
32-
"github.com/op/go-logging"
3333
"google.golang.org/grpc"
3434
)
3535

@@ -90,7 +90,7 @@ func (jcm *joinChannelMessage) AnchorPeers() []api.AnchorPeer {
9090
return jcm.anchorPeers
9191
}
9292

93-
var logger = logging.MustGetLogger("gossipService")
93+
var logger = util.GetLogger(util.LoggingServiceModule, "")
9494

9595
// InitGossipService initialize gossip service
9696
func InitGossipService(identity []byte, endpoint string, s *grpc.Server, bootPeers ...string) {

gossip/state/payloads_buffer.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"sync/atomic"
2424

2525
"github.com/hyperledger/fabric/gossip/proto"
26+
"github.com/hyperledger/fabric/gossip/util"
2627
"github.com/op/go-logging"
2728
)
2829

@@ -66,12 +67,11 @@ type PayloadsBufferImpl struct {
6667

6768
// NewPayloadsBuffer is factory function to create new payloads buffer
6869
func NewPayloadsBuffer(next uint64) PayloadsBuffer {
69-
logger, _ := logging.GetLogger("GossipStateProvider")
7070
return &PayloadsBufferImpl{
7171
buf: make(map[uint64]*proto.Payload),
7272
readyChan: make(chan struct{}, 0),
7373
next: next,
74-
logger: logger,
74+
logger: util.GetLogger(util.LoggingStateModule, ""),
7575
}
7676
}
7777

gossip/state/state.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
common2 "github.com/hyperledger/fabric/gossip/common"
3030
"github.com/hyperledger/fabric/gossip/gossip"
3131
"github.com/hyperledger/fabric/gossip/proto"
32+
"github.com/hyperledger/fabric/gossip/util"
3233
"github.com/hyperledger/fabric/protos/common"
3334
"github.com/op/go-logging"
3435
)
@@ -47,10 +48,6 @@ type GossipStateProvider interface {
4748
Stop()
4849
}
4950

50-
var logFormat = logging.MustStringFormatter(
51-
`%{color}%{level} %{longfunc}():%{color:reset}(%{module})%{message}`,
52-
)
53-
5451
var remoteStateMsgFilter = func(message interface{}) bool {
5552
return message.(comm.ReceivedMessage).GetGossipMessage().IsRemoteStateMessage()
5653
}
@@ -92,7 +89,7 @@ type GossipStateProviderImpl struct {
9289

9390
// NewGossipStateProvider creates initialized instance of gossip state provider
9491
func NewGossipStateProvider(chainID string, g gossip.Gossip, committer committer.Committer) GossipStateProvider {
95-
logger, _ := logging.GetLogger("GossipStateProvider")
92+
logger := util.GetLogger(util.LoggingStateModule, "")
9693

9794
gossipChan, _ := g.Accept(func(message interface{}) bool {
9895
// Get only data messages
@@ -133,8 +130,6 @@ func NewGossipStateProvider(chainID string, g gossip.Gossip, committer committer
133130
logger: logger,
134131
}
135132

136-
logging.SetFormatter(logFormat)
137-
138133
state := NewNodeMetastate(height - 1)
139134

140135
s.logger.Infof("Updating node metadata information, current ledger sequence is at = %d, next expected block is = %d", state.LedgerHeight, s.payloads.Next())

gossip/state/state_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ import (
3535
"github.com/hyperledger/fabric/gossip/common"
3636
"github.com/hyperledger/fabric/gossip/gossip"
3737
"github.com/hyperledger/fabric/gossip/proto"
38+
gossipUtil "github.com/hyperledger/fabric/gossip/util"
3839
pcomm "github.com/hyperledger/fabric/protos/common"
39-
"github.com/op/go-logging"
4040
"github.com/spf13/viper"
4141
"github.com/stretchr/testify/assert"
4242
)
4343

4444
var (
4545
portPrefix = 5610
46-
logger, _ = logging.GetLogger("GossipStateProviderTest")
46+
logger = gossipUtil.GetLogger(gossipUtil.LoggingStateModule, "")
4747
)
4848

4949
var orgId = []byte("ORG1")

0 commit comments

Comments
 (0)