build: switch to slog Handlers

Start using the new slog handlers. With this commit we also remove the
need for the LogWriter since we let our LogRotator implement io.Writer
and pass that in to our log file handler.
This commit is contained in:
Elle Mouton committed 2024-10-22 17:03:51 +02:00
1 parent 9a9761008c
commit cd697913ef
11 files changed
+130 -116

No files matched your search

+15 -8
View File
@@ -21,6 +21,7 @@ import (
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btclog/v2"
flags "github.com/jessevdk/go-flags"
"github.com/lightninglabs/neutrino"
"github.com/lightningnetwork/lnd/autopilot"
@@ -497,7 +498,6 @@ type Config struct {
// SubLogMgr is the root logger that all the daemon's subloggers are
// hooked up to.
SubLogMgr *build.SubLoggerManager
LogWriter *build.LogWriter
LogRotator *build.RotatingLogWriter
// networkDir is the path to the directory of the currently active
@@ -716,7 +716,7 @@ func DefaultConfig() Config {
MaxChannelFeeAllocation: htlcswitch.DefaultMaxLinkFeeAllocation,
MaxCommitFeeRateAnchors: lnwallet.DefaultAnchorsCommitMaxFeeRateSatPerVByte,
MaxFeeExposure: uint64(htlcswitch.DefaultMaxFeeExposure.ToSatoshis()),
LogWriter: &build.LogWriter{},
LogRotator: build.NewRotatingLogWriter(),
DB: lncfg.DefaultDB(),
Cluster: lncfg.DefaultCluster(),
RPCMiddleware: lncfg.DefaultRPCMiddleware(),
@@ -1402,10 +1402,18 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser,
lncfg.NormalizeNetwork(cfg.ActiveNetParams.Name),
)
// A log writer must be passed in, otherwise we can't function and would
// run into a panic later on.
if cfg.LogWriter == nil {
return nil, mkErr("log writer missing in config")
var (
consoleLogHander = btclog.NewDefaultHandler(os.Stdout)
logHandlers []btclog.Handler
)
switch build.LoggingType {
case build.LogTypeStdOut:
logHandlers = []btclog.Handler{consoleLogHander}
case build.LogTypeDefault:
logHandlers = []btclog.Handler{
consoleLogHander,
btclog.NewDefaultHandler(cfg.LogRotator),
}
}
if !build.SuportedLogCompressor(cfg.LogCompressor) {
@@ -1413,8 +1421,7 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser,
cfg.LogCompressor)
}
cfg.LogRotator = build.NewRotatingLogWriter(cfg.LogWriter)
cfg.SubLogMgr = build.NewSubLoggerManager(cfg.LogWriter)
cfg.SubLogMgr = build.NewSubLoggerManager(logHandlers...)
// Initialize logging at the default logging level.
SetupLoggers(cfg.SubLogMgr, interceptor)