mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-18 21:35:24 +01:00
tor: add logging to tor controller
This commit is contained in:
parent
a101a53eb4
commit
0b80d4feaa
2
log.go
2
log.go
@ -40,6 +40,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/rpcperms"
|
||||
"github.com/lightningnetwork/lnd/signal"
|
||||
"github.com/lightningnetwork/lnd/sweep"
|
||||
"github.com/lightningnetwork/lnd/tor"
|
||||
"github.com/lightningnetwork/lnd/watchtower"
|
||||
"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, cluster.Subsystem, interceptor, cluster.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
|
||||
|
@ -122,6 +122,8 @@ func (c *Controller) Start() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Info("Starting tor controller")
|
||||
|
||||
conn, err := textproto.Dial("tcp", c.controlAddr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to connect to Tor server: %v", err)
|
||||
@ -138,6 +140,8 @@ func (c *Controller) Stop() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Info("Stopping tor controller")
|
||||
|
||||
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
|
||||
// text protocol responses.
|
||||
code, reply, err := c.conn.Reader.ReadResponse(success)
|
||||
log.Tracef("sendCommand: %v got <code:%v>, <reply:%v>",
|
||||
command, code, reply)
|
||||
|
||||
if err != nil {
|
||||
log.Debugf("sendCommand:%s got err:%v, reply:%v",
|
||||
command, err, reply)
|
||||
return code, reply, err
|
||||
}
|
||||
|
||||
|
26
tor/log.go
Normal file
26
tor/log.go
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user