2
0
mirror of https://github.com/lightninglabs/loop synced 2024-11-13 13:10:30 +00:00
loop/loopd/log.go

62 lines
1.8 KiB
Go
Raw Normal View History

package loopd
2019-03-06 20:13:50 +00:00
import (
"github.com/btcsuite/btclog"
"github.com/lightninglabs/aperture/lsat"
"github.com/lightninglabs/lndclient"
2019-10-28 16:06:07 +00:00
"github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/liquidity"
2019-10-28 16:06:07 +00:00
"github.com/lightninglabs/loop/loopdb"
"github.com/lightningnetwork/lnd"
2019-10-28 16:06:07 +00:00
"github.com/lightningnetwork/lnd/build"
"github.com/lightningnetwork/lnd/signal"
2019-03-06 20:13:50 +00:00
)
const Subsystem = "LOOPD"
2019-10-28 16:06:07 +00:00
var (
logWriter *build.RotatingLogWriter
log btclog.Logger
interceptor signal.Interceptor
2019-03-06 20:13:50 +00:00
)
// SetupLoggers initializes all package-global logger variables.
func SetupLoggers(root *build.RotatingLogWriter, intercept signal.Interceptor) {
genLogger := genSubLogger(root, intercept)
logWriter = root
log = build.NewSubLogger(Subsystem, genLogger)
interceptor = intercept
2019-10-28 16:06:07 +00:00
lnd.SetSubLogger(root, Subsystem, log)
lnd.AddSubLogger(root, "LOOP", intercept, loop.UseLogger)
lnd.AddSubLogger(root, "LNDC", intercept, lndclient.UseLogger)
lnd.AddSubLogger(root, "STORE", intercept, loopdb.UseLogger)
lnd.AddSubLogger(root, lsat.Subsystem, intercept, lsat.UseLogger)
lnd.AddSubLogger(
root, liquidity.Subsystem, intercept, liquidity.UseLogger,
)
2019-10-28 16:06:07 +00:00
}
// genSubLogger creates a logger for a subsystem. We provide an instance of
// a signal.Interceptor to be able to shutdown in the case of a critical error.
func genSubLogger(root *build.RotatingLogWriter,
interceptor signal.Interceptor) func(string) btclog.Logger {
// Create a shutdown function which will request shutdown from our
// interceptor if it is listening.
shutdown := func() {
if !interceptor.Listening() {
return
}
interceptor.RequestShutdown()
}
2019-03-06 20:13:50 +00:00
// Return a function which will create a sublogger from our root
// logger without shutdown fn.
return func(tag string) btclog.Logger {
return root.GenSubLogger(tag, shutdown)
2019-10-28 16:06:07 +00:00
}
2019-03-06 20:13:50 +00:00
}