Skip to content

Commit 8667c50

Browse files
committed
log: unified static address logger
1 parent 0a35bf6 commit 8667c50

File tree

6 files changed

+56
-24
lines changed

6 files changed

+56
-24
lines changed

loopd/log.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/lightninglabs/loop/instantout/reservation"
1111
"github.com/lightninglabs/loop/liquidity"
1212
"github.com/lightninglabs/loop/loopdb"
13+
"github.com/lightninglabs/loop/staticaddr"
1314
"github.com/lightninglabs/loop/sweepbatcher"
1415
"github.com/lightningnetwork/lnd"
1516
"github.com/lightningnetwork/lnd/build"
@@ -38,6 +39,9 @@ func SetupLoggers(root *build.RotatingLogWriter, intercept signal.Interceptor) {
3839
lnd.AddSubLogger(root, "LNDC", intercept, lndclient.UseLogger)
3940
lnd.AddSubLogger(root, "STORE", intercept, loopdb.UseLogger)
4041
lnd.AddSubLogger(root, l402.Subsystem, intercept, l402.UseLogger)
42+
lnd.AddSubLogger(
43+
root, staticaddr.Subsystem, intercept, staticaddr.UseLogger,
44+
)
4145
lnd.AddSubLogger(
4246
root, liquidity.Subsystem, intercept, liquidity.UseLogger,
4347
)

staticaddr/address/log.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package address
2+
3+
import (
4+
"github.com/btcsuite/btclog"
5+
"github.com/lightningnetwork/lnd/build"
6+
)
7+
8+
// Subsystem defines the sub system name of this package.
9+
const Subsystem = "SADDR"
10+
11+
// log is a logger that is initialized with no output filters. This means the
12+
// package will not perform any logging by default until the caller requests it.
13+
var log btclog.Logger
14+
15+
// The default amount of logging is none.
16+
func init() {
17+
UseLogger(build.NewSubLogger(Subsystem, nil))
18+
}
19+
20+
// UseLogger uses a specified Logger to output package logging info. This should
21+
// be used in preference to SetLogWriter if the caller is also using btclog.
22+
func UseLogger(logger btclog.Logger) {
23+
log = logger
24+
}

staticaddr/address/manager.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/btcsuite/btcd/btcec/v2/schnorr"
1111
"github.com/btcsuite/btcd/btcutil"
1212
"github.com/btcsuite/btcd/chaincfg"
13-
"github.com/btcsuite/btclog"
1413
"github.com/lightninglabs/lndclient"
1514
"github.com/lightninglabs/loop/staticaddr"
1615
"github.com/lightninglabs/loop/staticaddr/script"
@@ -22,14 +21,6 @@ import (
2221
"github.com/lightningnetwork/lnd/lnwallet"
2322
)
2423

25-
var (
26-
log btclog.Logger
27-
)
28-
29-
func init() {
30-
log = staticaddr.GetLogger()
31-
}
32-
3324
// ManagerConfig holds the configuration for the address manager.
3425
type ManagerConfig struct {
3526
// AddressClient is the client that communicates with the loop server

staticaddr/deposit/log.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package deposit
2+
3+
import (
4+
"github.com/btcsuite/btclog"
5+
"github.com/lightningnetwork/lnd/build"
6+
)
7+
8+
// Subsystem defines the sub system name of this package.
9+
const Subsystem = "SADDR"
10+
11+
// log is a logger that is initialized with no output filters. This means the
12+
// package will not perform any logging by default until the caller requests it.
13+
var log btclog.Logger
14+
15+
// The default amount of logging is none.
16+
func init() {
17+
UseLogger(build.NewSubLogger(Subsystem, nil))
18+
}
19+
20+
// UseLogger uses a specified Logger to output package logging info. This should
21+
// be used in preference to SetLogWriter if the caller is also using btclog.
22+
func UseLogger(logger btclog.Logger) {
23+
log = logger
24+
}

staticaddr/deposit/manager.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ import (
99
"github.com/btcsuite/btcd/chaincfg"
1010
"github.com/btcsuite/btcd/txscript"
1111
"github.com/btcsuite/btcd/wire"
12-
"github.com/btcsuite/btclog"
1312
"github.com/lightninglabs/lndclient"
1413
"github.com/lightninglabs/loop"
15-
"github.com/lightninglabs/loop/staticaddr"
1614
staticaddressrpc "github.com/lightninglabs/loop/swapserverrpc"
1715
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
1816
"github.com/lightningnetwork/lnd/lnwallet"
@@ -33,14 +31,6 @@ const (
3331
MaxConfs = 0
3432
)
3533

36-
var (
37-
log btclog.Logger
38-
)
39-
40-
func init() {
41-
log = staticaddr.GetLogger()
42-
}
43-
4434
// ManagerConfig holds the configuration for the address manager.
4535
type ManagerConfig struct {
4636
// AddressClient is the client that communicates with the loop server

staticaddr/log.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package staticaddr
22

33
import (
44
"github.com/btcsuite/btclog"
5+
"github.com/lightninglabs/loop/staticaddr/address"
6+
"github.com/lightninglabs/loop/staticaddr/deposit"
57
"github.com/lightningnetwork/lnd/build"
68
)
79

@@ -21,9 +23,6 @@ func init() {
2123
// be used in preference to SetLogWriter if the caller is also using btclog.
2224
func UseLogger(logger btclog.Logger) {
2325
log = logger
24-
}
25-
26-
// GetLogger returns the logger for this package.
27-
func GetLogger() btclog.Logger {
28-
return log
26+
address.UseLogger(log)
27+
deposit.UseLogger(log)
2928
}

0 commit comments

Comments
 (0)