Skip to content

Commit e835163

Browse files
committed
config: set log level after setting up loggers
To make sure we set the log level for all registered loggers, we need to move the call that sets the level. Since we only have one root logger, we can only use one value for the global level. So we use the --remote.lit-debuglevel in remote lnd mode and the --lnd.debuglevel in integrated mode. Individual sub loggers can still be overwritten if the following syntax is used: --lnd.debuglevel=debug,AUCT=trace for example.
1 parent a5a4828 commit e835163

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

config.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,23 @@ func loadAndValidateConfig(interceptor signal.Interceptor) (*Config, error) {
336336
cfg.loopRemote = cfg.LoopMode == ModeRemote
337337
cfg.poolRemote = cfg.PoolMode == ModeRemote
338338

339+
// Now that we've registered all loggers, let's parse, validate, and set
340+
// the debug log level(s). In remote lnd mode we have a global log level
341+
// that overwrites all others. In integrated mode we use the lnd log
342+
// level as the master level.
343+
if cfg.lndRemote {
344+
err = build.ParseAndSetDebugLevels(
345+
cfg.Remote.LitDebugLevel, cfg.Lnd.LogWriter,
346+
)
347+
} else {
348+
err = build.ParseAndSetDebugLevels(
349+
cfg.Lnd.DebugLevel, cfg.Lnd.LogWriter,
350+
)
351+
}
352+
if err != nil {
353+
return nil, err
354+
}
355+
339356
// Validate the lightning-terminal config options.
340357
litDir := lnd.CleanAndExpandPath(preCfg.LitDir)
341358
cfg.LetsEncryptDir = lncfg.CleanAndExpandPath(cfg.LetsEncryptDir)
@@ -576,21 +593,21 @@ func validateRemoteModeConfig(cfg *Config) error {
576593
}
577594

578595
// In remote mode, we don't call lnd's ValidateConfig that sets up a
579-
// logging backend for us. We need to manually create and start one.
580-
logWriter := build.NewRotatingLogWriter()
581-
cfg.Lnd.LogWriter = logWriter
582-
err := logWriter.InitLogRotator(
596+
// logging backend for us. We need to manually create and start one. The
597+
// root logger should've already been created as part of the default
598+
// config though.
599+
if cfg.Lnd.LogWriter == nil {
600+
cfg.Lnd.LogWriter = build.NewRotatingLogWriter()
601+
}
602+
err := cfg.Lnd.LogWriter.InitLogRotator(
583603
filepath.Join(r.LitLogDir, cfg.Network, defaultLogFilename),
584604
r.LitMaxLogFileSize, r.LitMaxLogFiles,
585605
)
586606
if err != nil {
587607
return fmt.Errorf("log rotation setup failed: %v", err.Error())
588608
}
589609

590-
// Parse, validate, and set debug log level(s).
591-
return build.ParseAndSetDebugLevels(
592-
cfg.Remote.LitDebugLevel, logWriter,
593-
)
610+
return nil
594611
}
595612

596613
// setNetwork parses the top-level network config options and, if valid, sets it

0 commit comments

Comments
 (0)