mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-03 06:37:14 +00:00
libs/service: pass logger explicitly (#7288)
This is a very small change, but removes a method from the `service.Service` interface (a win!) and forces callers to explicitly pass loggers in to objects during construction rather than (later) injecting them. There's not a real need for this kind of lazy construction of loggers, and I think a decent potential for confusion for mutable loggers. The main concern I have is that this changes the constructor API for ABCI clients. I think this is fine, and I suspect that as we plumb contexts through, and make changes to the RPC services there'll be a number of similar sorts of changes to various (quasi) public interfaces, which I think we should welcome.
This commit is contained in:
@@ -136,10 +136,10 @@ type Option func(*Server)
|
||||
// provided, the resulting server's queue is unbuffered.
|
||||
func NewServer(options ...Option) *Server {
|
||||
s := new(Server)
|
||||
s.BaseService = *service.NewBaseService(nil, "PubSub", s)
|
||||
for _, opt := range options {
|
||||
opt(s)
|
||||
}
|
||||
s.BaseService = *service.NewBaseService(nil, "PubSub", s)
|
||||
|
||||
// The queue receives items to be published.
|
||||
s.queue = make(chan item, s.queueCap)
|
||||
|
||||
@@ -357,8 +357,10 @@ func TestUnsubscribeAll(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBufferCapacity(t *testing.T) {
|
||||
s := pubsub.NewServer(pubsub.BufferCapacity(2))
|
||||
s.SetLogger(log.TestingLogger())
|
||||
s := pubsub.NewServer(pubsub.BufferCapacity(2),
|
||||
func(s *pubsub.Server) {
|
||||
s.Logger = log.TestingLogger()
|
||||
})
|
||||
|
||||
require.Equal(t, 2, s.BufferCapacity())
|
||||
|
||||
@@ -376,8 +378,10 @@ func TestBufferCapacity(t *testing.T) {
|
||||
func newTestServer(t testing.TB) *pubsub.Server {
|
||||
t.Helper()
|
||||
|
||||
s := pubsub.NewServer()
|
||||
s.SetLogger(log.TestingLogger())
|
||||
s := pubsub.NewServer(func(s *pubsub.Server) {
|
||||
s.Logger = log.TestingLogger()
|
||||
})
|
||||
|
||||
require.NoError(t, s.Start())
|
||||
t.Cleanup(func() {
|
||||
assert.NoError(t, s.Stop())
|
||||
|
||||
@@ -48,9 +48,6 @@ type Service interface {
|
||||
// String representation of the service
|
||||
String() string
|
||||
|
||||
// SetLogger sets a logger.
|
||||
SetLogger(log.Logger)
|
||||
|
||||
// Wait blocks until the service is stopped.
|
||||
Wait()
|
||||
}
|
||||
@@ -122,11 +119,6 @@ func NewBaseService(logger log.Logger, name string, impl Service) *BaseService {
|
||||
}
|
||||
}
|
||||
|
||||
// SetLogger implements Service by setting a logger.
|
||||
func (bs *BaseService) SetLogger(l log.Logger) {
|
||||
bs.Logger = l
|
||||
}
|
||||
|
||||
// Start implements Service by calling OnStart (if defined). An error will be
|
||||
// returned if the service is already running or stopped. Not to start the
|
||||
// stopped service, you need to call Reset.
|
||||
|
||||
Reference in New Issue
Block a user