Skip to content

Commit f7d7bb9

Browse files
committed
mobile: bindings
1 parent e7929d8 commit f7d7bb9

File tree

2 files changed

+551
-0
lines changed

2 files changed

+551
-0
lines changed

mobile/log.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package mobile
2+
3+
import (
4+
"github.com/btcsuite/btclog"
5+
"github.com/lightninglabs/lightning-node-connect/mailbox"
6+
"github.com/lightningnetwork/lnd"
7+
"github.com/lightningnetwork/lnd/build"
8+
"github.com/lightningnetwork/lnd/signal"
9+
"google.golang.org/grpc/grpclog"
10+
)
11+
12+
const Subsystem = "MOBL"
13+
14+
var (
15+
log btclog.Logger
16+
)
17+
18+
// SetupLoggers initializes all package-global logger variables.
19+
func SetupLoggers(root *build.RotatingLogWriter, intercept signal.Interceptor) {
20+
genLogger := genSubLogger(root, intercept)
21+
22+
log = build.NewSubLogger(Subsystem, genLogger)
23+
24+
lnd.SetSubLogger(root, Subsystem, log)
25+
lnd.AddSubLogger(root, mailbox.Subsystem, intercept, mailbox.UseLogger)
26+
27+
grpclog.SetLoggerV2(NewGrpcLogLogger(root, intercept, "GRPC"))
28+
}
29+
30+
// genSubLogger creates a logger for a subsystem. We provide an instance of
31+
// a signal.Interceptor to be able to shutdown in the case of a critical error.
32+
func genSubLogger(root *build.RotatingLogWriter,
33+
interceptor signal.Interceptor) func(string) btclog.Logger {
34+
35+
// Create a shutdown function which will request shutdown from our
36+
// interceptor if it is listening.
37+
shutdown := func() {
38+
if !interceptor.Listening() {
39+
return
40+
}
41+
42+
interceptor.RequestShutdown()
43+
}
44+
45+
// Return a function which will create a sublogger from our root
46+
// logger without shutdown fn.
47+
return func(tag string) btclog.Logger {
48+
return root.GenSubLogger(tag, shutdown)
49+
}
50+
}
51+
52+
// NewGrpcLogLogger creates a new grpclog compatible logger and attaches it as
53+
// a sub logger to the passed root logger.
54+
func NewGrpcLogLogger(root *build.RotatingLogWriter,
55+
intercept signal.Interceptor, subsystem string) *mailbox.GrpcLogLogger {
56+
57+
logger := build.NewSubLogger(subsystem, genSubLogger(root, intercept))
58+
lnd.SetSubLogger(root, subsystem, logger)
59+
return &mailbox.GrpcLogLogger{
60+
Logger: logger,
61+
}
62+
}

0 commit comments

Comments
 (0)