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.
case PaymentResultSuccess:
logger.Infof(
log.Infof(
"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.
case PaymentResultAlreadyPaid:
logger.Infof(
log.Infof(
"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
// tracking existing payments.
case PaymentResultInFlight:
logger.Infof(
log.Infof(
"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.
default:
logger.Warnf(
log.Warnf(
"Payment %v failed: %v", hash,
payResp.PaymentError,
)

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

@ -2,22 +2,28 @@ package lndclient
import (
"github.com/btcsuite/btclog"
"os"
"github.com/lightningnetwork/lnd/build"
)
// 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 (
backendLog = btclog.NewBackend(logWriter{})
logger = backendLog.Logger("LNDCLIENT")
)
// 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("LNDC", nil))
}
// logWriter implements an io.Writer that outputs to both standard output and
// the write-end pipe of an initialized log rotator.
type logWriter struct{}
// DisableLog disables all library log output. Logging output is disabled by
// default until UseLogger is called.
func DisableLog() {
UseLogger(btclog.Disabled)
}
func (logWriter) Write(p []byte) (n int, err error) {
os.Stdout.Write(p)
return len(p), nil
// 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…
Cancel
Save