lndclient: use lnd's build package for logging

pull/30/head
Olaoluwa Osuntokun 5 years ago
parent b45956b84f
commit 9a824d88b1
No known key found for this signature in database
GPG Key ID: CE58F7F8E20FD9A2

@ -240,7 +240,7 @@ func (s *lightningClient) payInvoice(ctx context.Context, invoice string,
// Paid successfully. // Paid successfully.
case PaymentResultSuccess: case PaymentResultSuccess:
logger.Infof( log.Infof(
"Payment %v completed", hash, "Payment %v completed", hash,
) )
@ -261,7 +261,7 @@ func (s *lightningClient) payInvoice(ctx context.Context, invoice string,
// Invoice was already paid on a previous run. // Invoice was already paid on a previous run.
case PaymentResultAlreadyPaid: case PaymentResultAlreadyPaid:
logger.Infof( log.Infof(
"Payment %v already completed", hash, "Payment %v already completed", hash,
) )
@ -281,7 +281,7 @@ func (s *lightningClient) payInvoice(ctx context.Context, invoice string,
// TODO: Improve this when lnd expose more API to // TODO: Improve this when lnd expose more API to
// tracking existing payments. // tracking existing payments.
case PaymentResultInFlight: case PaymentResultInFlight:
logger.Infof( log.Infof(
"Payment %v already in flight", hash, "Payment %v already in flight", hash,
) )
@ -289,7 +289,7 @@ func (s *lightningClient) payInvoice(ctx context.Context, invoice string,
// Other errors are transformed into an error struct. // Other errors are transformed into an error struct.
default: default:
logger.Warnf( log.Warnf(
"Payment %v failed: %v", hash, "Payment %v failed: %v", hash,
payResp.PaymentError, payResp.PaymentError,
) )

@ -45,13 +45,13 @@ func NewLndServices(lndAddress string, application string,
*GrpcLndServices, error) { *GrpcLndServices, error) {
// Setup connection with lnd // Setup connection with lnd
logger.Infof("Creating lnd connection to %v", lndAddress) log.Infof("Creating lnd connection to %v", lndAddress)
conn, err := getClientConn(lndAddress, network, macPath, tlsPath) conn, err := getClientConn(lndAddress, network, macPath, tlsPath)
if err != nil { if err != nil {
return nil, err return nil, err
} }
logger.Infof("Connected to lnd") log.Infof("Connected to lnd")
chainParams, err := swap.ChainParamsFromNetwork(network) chainParams, err := swap.ChainParamsFromNetwork(network)
if err != nil { if err != nil {
@ -78,19 +78,19 @@ func NewLndServices(lndAddress string, application string,
invoicesClient := newInvoicesClient(conn) invoicesClient := newInvoicesClient(conn)
cleanup := func() { cleanup := func() {
logger.Debugf("Closing lnd connection") log.Debugf("Closing lnd connection")
conn.Close() conn.Close()
logger.Debugf("Wait for client to finish") log.Debugf("Wait for client to finish")
lightningClient.WaitForFinished() lightningClient.WaitForFinished()
logger.Debugf("Wait for chain notifier to finish") log.Debugf("Wait for chain notifier to finish")
notifierClient.WaitForFinished() notifierClient.WaitForFinished()
logger.Debugf("Wait for invoices to finish") log.Debugf("Wait for invoices to finish")
invoicesClient.WaitForFinished() invoicesClient.WaitForFinished()
logger.Debugf("Lnd services finished") log.Debugf("Lnd services finished")
} }
services := &GrpcLndServices{ services := &GrpcLndServices{
@ -105,7 +105,7 @@ func NewLndServices(lndAddress string, application string,
cleanup: cleanup, cleanup: cleanup,
} }
logger.Infof("Using network %v", network) log.Infof("Using network %v", network)
return services, nil return services, nil
} }
@ -115,7 +115,7 @@ func NewLndServices(lndAddress string, application string,
func (s *GrpcLndServices) Close() { func (s *GrpcLndServices) Close() {
s.cleanup() s.cleanup()
logger.Debugf("Lnd services finished") log.Debugf("Lnd services finished")
} }
var ( var (

@ -2,22 +2,28 @@ package lndclient
import ( import (
"github.com/btcsuite/btclog" "github.com/btcsuite/btclog"
"os" "github.com/lightningnetwork/lnd/build"
) )
// log is a logger that is initialized with no output filters. This // log is a logger that is initialized with no output filters. This means the
// means the package will not perform any logging by default until the caller // package will not perform any logging by default until the caller requests
// requests it. // it.
var ( var log btclog.Logger
backendLog = btclog.NewBackend(logWriter{})
logger = backendLog.Logger("LNDCLIENT") // The default amount of logging is none.
) func init() {
UseLogger(build.NewSubLogger("LNDC", nil))
}
// logWriter implements an io.Writer that outputs to both standard output and // DisableLog disables all library log output. Logging output is disabled by
// the write-end pipe of an initialized log rotator. // default until UseLogger is called.
type logWriter struct{} func DisableLog() {
UseLogger(btclog.Disabled)
}
func (logWriter) Write(p []byte) (n int, err error) { // UseLogger uses a specified Logger to output package logging info. This
os.Stdout.Write(p) // should be used in preference to SetLogWriter if the caller is also using
return len(p), nil // btclog.
func UseLogger(logger btclog.Logger) {
log = logger
} }

Loading…
Cancel
Save