From b195d39ad75c2106bcf1fbfc436f2b072df630b3 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Mon, 11 May 2020 16:05:04 -0700 Subject: [PATCH] rpc: use existing rpc logger for wtclientrpc The logger string used to identify the wtclient and wtclientrpc loggers was the same, leading to being unable to modify the log level of the wtclient logger as it would be overwritten with the wtclientrpc's one. To simplify things, we decide to use the existing RPC logger for wtclientrpc. --- lnrpc/wtclientrpc/config.go | 4 +++ lnrpc/wtclientrpc/log.go | 48 ----------------------------------- lnrpc/wtclientrpc/wtclient.go | 4 +-- log.go | 2 -- rpcserver.go | 1 + subrpcserver_config.go | 7 ++++- 6 files changed, 13 insertions(+), 53 deletions(-) delete mode 100644 lnrpc/wtclientrpc/log.go diff --git a/lnrpc/wtclientrpc/config.go b/lnrpc/wtclientrpc/config.go index a008ca0d38..8796bd0569 100644 --- a/lnrpc/wtclientrpc/config.go +++ b/lnrpc/wtclientrpc/config.go @@ -1,6 +1,7 @@ package wtclientrpc import ( + "github.com/btcsuite/btclog" "github.com/lightningnetwork/lnd/lncfg" "github.com/lightningnetwork/lnd/watchtower/wtclient" ) @@ -22,4 +23,7 @@ type Config struct { // addresses to ensure we don't leak any information when running over // non-clear networks, e.g. Tor, etc. Resolver lncfg.TCPResolver + + // Log is the logger instance we should log output to. + Log btclog.Logger } diff --git a/lnrpc/wtclientrpc/log.go b/lnrpc/wtclientrpc/log.go deleted file mode 100644 index eaa847d647..0000000000 --- a/lnrpc/wtclientrpc/log.go +++ /dev/null @@ -1,48 +0,0 @@ -package wtclientrpc - -import ( - "github.com/btcsuite/btclog" - "github.com/lightningnetwork/lnd/build" -) - -// Subsystem defines the logging code for this subsystem. -const Subsystem = "WTCL" - -// log is a logger that is initialized with no output filters. This means the -// package will not perform any logging by default until the caller requests -// it. -var log btclog.Logger - -// The default amount of logging is none. -func init() { - UseLogger(build.NewSubLogger(Subsystem, nil)) -} - -// DisableLog disables all library log output. Logging output is disabled by -// by default until UseLogger is called. -func DisableLog() { - UseLogger(btclog.Disabled) -} - -// UseLogger uses a specified Logger to output package logging info. This -// should be used in preference to SetLogWriter if the caller is also using -// btclog. -func UseLogger(logger btclog.Logger) { - log = logger -} - -// logClosure is used to provide a closure over expensive logging operations so -// don't have to be performed when the logging level doesn't warrant it. -type logClosure func() string // nolint:unused - -// String invokes the underlying function and returns the result. -func (c logClosure) String() string { - return c() -} - -// newLogClosure returns a new closure over a function that returns a string -// which itself provides a Stringer interface so that it can be used with the -// logging system. -func newLogClosure(c func() string) logClosure { // nolint:unused - return logClosure(c) -} diff --git a/lnrpc/wtclientrpc/wtclient.go b/lnrpc/wtclientrpc/wtclient.go index 8cbdc9bfa9..b6f1fa2a8f 100644 --- a/lnrpc/wtclientrpc/wtclient.go +++ b/lnrpc/wtclientrpc/wtclient.go @@ -115,8 +115,8 @@ func (c *WatchtowerClient) RegisterWithRootServer(grpcServer *grpc.Server) error // all our methods are routed properly. RegisterWatchtowerClientServer(grpcServer, c) - log.Debugf("WatchtowerClient RPC server successfully registered with " + - "root gRPC server") + c.cfg.Log.Debugf("WatchtowerClient RPC server successfully registered " + + "with root gRPC server") return nil } diff --git a/log.go b/log.go index 51754cca54..abd1672690 100644 --- a/log.go +++ b/log.go @@ -25,7 +25,6 @@ import ( "github.com/lightningnetwork/lnd/lnrpc/signrpc" "github.com/lightningnetwork/lnd/lnrpc/verrpc" "github.com/lightningnetwork/lnd/lnrpc/walletrpc" - "github.com/lightningnetwork/lnd/lnrpc/wtclientrpc" "github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet/chanfunding" "github.com/lightningnetwork/lnd/monitoring" @@ -102,7 +101,6 @@ func init() { addSubLogger(routing.Subsystem, routing.UseLogger, localchans.UseLogger) addSubLogger(routerrpc.Subsystem, routerrpc.UseLogger) - addSubLogger(wtclientrpc.Subsystem, wtclientrpc.UseLogger) addSubLogger(chanfitness.Subsystem, chanfitness.UseLogger) addSubLogger(verrpc.Subsystem, verrpc.UseLogger) } diff --git a/rpcserver.go b/rpcserver.go index c725b67b44..d014daf420 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -589,6 +589,7 @@ func newRPCServer(s *server, macService *macaroons.Service, s.htlcSwitch, activeNetParams.Params, s.chanRouter, routerBackend, s.nodeSigner, s.chanDB, s.sweeper, tower, s.towerClient, cfg.net.ResolveTCPAddr, genInvoiceFeatures, + rpcsLog, ) if err != nil { return nil, err diff --git a/subrpcserver_config.go b/subrpcserver_config.go index 316320289f..5c87f3abd3 100644 --- a/subrpcserver_config.go +++ b/subrpcserver_config.go @@ -5,6 +5,7 @@ import ( "reflect" "github.com/btcsuite/btcd/chaincfg" + "github.com/btcsuite/btclog" "github.com/lightningnetwork/lnd/autopilot" "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/htlcswitch" @@ -94,7 +95,8 @@ func (s *subRPCServerConfigs) PopulateDependencies(cc *chainControl, tower *watchtower.Standalone, towerClient wtclient.Client, tcpResolver lncfg.TCPResolver, - genInvoiceFeatures func() *lnwire.FeatureVector) error { + genInvoiceFeatures func() *lnwire.FeatureVector, + rpcLogger btclog.Logger) error { // First, we'll use reflect to obtain a version of the config struct // that allows us to programmatically inspect its fields. @@ -244,6 +246,9 @@ func (s *subRPCServerConfigs) PopulateDependencies(cc *chainControl, subCfgValue.FieldByName("Resolver").Set( reflect.ValueOf(tcpResolver), ) + subCfgValue.FieldByName("Log").Set( + reflect.ValueOf(rpcLogger), + ) default: return fmt.Errorf("unknown field: %v, %T", fieldName,