tor: add logging to tor controller

This commit is contained in:
yyforyongyu 2021-09-23 18:34:51 +08:00
parent a101a53eb4
commit 0b80d4feaa
No known key found for this signature in database
GPG Key ID: 9BCD95C4FF296868
3 changed files with 37 additions and 0 deletions

2
log.go
View File

@ -40,6 +40,7 @@ import (
"github.com/lightningnetwork/lnd/rpcperms" "github.com/lightningnetwork/lnd/rpcperms"
"github.com/lightningnetwork/lnd/signal" "github.com/lightningnetwork/lnd/signal"
"github.com/lightningnetwork/lnd/sweep" "github.com/lightningnetwork/lnd/sweep"
"github.com/lightningnetwork/lnd/tor"
"github.com/lightningnetwork/lnd/watchtower" "github.com/lightningnetwork/lnd/watchtower"
"github.com/lightningnetwork/lnd/watchtower/wtclient" "github.com/lightningnetwork/lnd/watchtower/wtclient"
) )
@ -161,6 +162,7 @@ func SetupLoggers(root *build.RotatingLogWriter, interceptor signal.Interceptor)
AddSubLogger(root, funding.Subsystem, interceptor, funding.UseLogger) AddSubLogger(root, funding.Subsystem, interceptor, funding.UseLogger)
AddSubLogger(root, cluster.Subsystem, interceptor, cluster.UseLogger) AddSubLogger(root, cluster.Subsystem, interceptor, cluster.UseLogger)
AddSubLogger(root, rpcperms.Subsystem, interceptor, rpcperms.UseLogger) AddSubLogger(root, rpcperms.Subsystem, interceptor, rpcperms.UseLogger)
AddSubLogger(root, tor.Subsystem, interceptor, tor.UseLogger)
} }
// AddSubLogger is a helper method to conveniently create and register the // AddSubLogger is a helper method to conveniently create and register the

View File

@ -122,6 +122,8 @@ func (c *Controller) Start() error {
return nil return nil
} }
log.Info("Starting tor controller")
conn, err := textproto.Dial("tcp", c.controlAddr) conn, err := textproto.Dial("tcp", c.controlAddr)
if err != nil { if err != nil {
return fmt.Errorf("unable to connect to Tor server: %v", err) return fmt.Errorf("unable to connect to Tor server: %v", err)
@ -138,6 +140,8 @@ func (c *Controller) Stop() error {
return nil return nil
} }
log.Info("Stopping tor controller")
return c.conn.Close() return c.conn.Close()
} }
@ -151,7 +155,12 @@ func (c *Controller) sendCommand(command string) (int, string, error) {
// We'll use ReadResponse as it has built-in support for multi-line // We'll use ReadResponse as it has built-in support for multi-line
// text protocol responses. // text protocol responses.
code, reply, err := c.conn.Reader.ReadResponse(success) code, reply, err := c.conn.Reader.ReadResponse(success)
log.Tracef("sendCommand: %v got <code:%v>, <reply:%v>",
command, code, reply)
if err != nil { if err != nil {
log.Debugf("sendCommand:%s got err:%v, reply:%v",
command, err, reply)
return code, reply, err return code, reply, err
} }

26
tor/log.go Normal file
View File

@ -0,0 +1,26 @@
package tor
import (
"github.com/btcsuite/btclog"
)
// Subsystem defines the logging code for this subsystem.
const Subsystem = "TORC" // TORC as in Tor Controller.
// 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.Disabled
// DisableLog disables all library log output. Logging output is disabled
// 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
}