Skip to content

Commit 5eff056

Browse files
committed
routing: prefix MC logs with namespace
1 parent f0f4f2d commit 5eff056

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

routing/missioncontrol.go

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import (
77
"time"
88

99
"github.com/btcsuite/btcd/btcutil"
10+
"github.com/btcsuite/btclog"
1011
"github.com/btcsuite/btcwallet/walletdb"
12+
"github.com/lightningnetwork/lnd/build"
1113
"github.com/lightningnetwork/lnd/channeldb"
1214
"github.com/lightningnetwork/lnd/clock"
1315
"github.com/lightningnetwork/lnd/fn"
@@ -127,6 +129,8 @@ type MissionControl struct {
127129
// mission control state is updated.
128130
onConfigUpdate fn.Option[func(cfg *MissionControlConfig)]
129131

132+
log btclog.Logger
133+
130134
mu sync.Mutex
131135
}
132136

@@ -270,10 +274,14 @@ func NewMissionController(db kvdb.Backend, self route.Vertex,
270274

271275
// Create a mission control in the default namespace.
272276
defaultMC := &MissionControl{
273-
cfg: mcCfg,
274-
state: newMissionControlState(cfg.MinFailureRelaxInterval),
275-
store: store,
276-
estimator: cfg.Estimator,
277+
cfg: mcCfg,
278+
state: newMissionControlState(cfg.MinFailureRelaxInterval),
279+
store: store,
280+
estimator: cfg.Estimator,
281+
log: build.NewPrefixLog(
282+
fmt.Sprintf("[%s]:", DefaultMissionControlNamespace),
283+
log,
284+
),
277285
onConfigUpdate: cfg.OnConfigUpdate,
278286
}
279287

@@ -310,7 +318,7 @@ func (m *MissionController) StopStoreTicker() {
310318

311319
// init initializes mission control with historical data.
312320
func (m *MissionControl) init() error {
313-
log.Debugf("Mission control state reconstruction started")
321+
m.log.Debugf("Mission control state reconstruction started")
314322

315323
m.mu.Lock()
316324
defer m.mu.Unlock()
@@ -326,7 +334,7 @@ func (m *MissionControl) init() error {
326334
_ = m.applyPaymentResult(result)
327335
}
328336

329-
log.Debugf("Mission control state reconstruction finished: "+
337+
m.log.Debugf("Mission control state reconstruction finished: "+
330338
"n=%v, time=%v", len(results), time.Since(start))
331339

332340
return nil
@@ -361,7 +369,7 @@ func (m *MissionControl) SetConfig(cfg *MissionControlConfig) error {
361369
m.mu.Lock()
362370
defer m.mu.Unlock()
363371

364-
log.Infof("Active mission control cfg: %v, estimator: %v", cfg,
372+
m.log.Infof("Active mission control cfg: %v, estimator: %v", cfg,
365373
cfg.Estimator)
366374

367375
m.store.maxRecords = cfg.MaxMcHistory
@@ -388,7 +396,7 @@ func (m *MissionControl) ResetHistory() error {
388396

389397
m.state.resetHistory()
390398

391-
log.Debugf("Mission control history cleared")
399+
m.log.Debugf("Mission control history cleared")
392400

393401
return nil
394402
}
@@ -420,7 +428,7 @@ func (m *MissionControl) GetHistorySnapshot() *MissionControlSnapshot {
420428
m.mu.Lock()
421429
defer m.mu.Unlock()
422430

423-
log.Debugf("Requesting history snapshot from mission control")
431+
m.log.Debugf("Requesting history snapshot from mission control")
424432

425433
return m.state.getSnapshot()
426434
}
@@ -438,12 +446,12 @@ func (m *MissionControl) ImportHistory(history *MissionControlSnapshot,
438446
m.mu.Lock()
439447
defer m.mu.Unlock()
440448

441-
log.Infof("Importing history snapshot with %v pairs to mission control",
442-
len(history.Pairs))
449+
m.log.Infof("Importing history snapshot with %v pairs to mission "+
450+
"control", len(history.Pairs))
443451

444452
imported := m.state.importSnapshot(history, force)
445453

446-
log.Infof("Imported %v results to mission control", imported)
454+
m.log.Infof("Imported %v results to mission control", imported)
447455

448456
return nil
449457
}
@@ -567,7 +575,7 @@ func (m *MissionControl) applyPaymentResult(
567575
// that case, a node-level failure would not be applied to untried
568576
// channels.
569577
if i.nodeFailure != nil {
570-
log.Debugf("Reporting node failure to Mission Control: "+
578+
m.log.Debugf("Reporting node failure to Mission Control: "+
571579
"node=%v", *i.nodeFailure)
572580

573581
m.state.setAllFail(*i.nodeFailure, result.timeReply)
@@ -577,11 +585,11 @@ func (m *MissionControl) applyPaymentResult(
577585
pairResult := pairResult
578586

579587
if pairResult.success {
580-
log.Debugf("Reporting pair success to Mission "+
588+
m.log.Debugf("Reporting pair success to Mission "+
581589
"Control: pair=%v, amt=%v",
582590
pair, pairResult.amt)
583591
} else {
584-
log.Debugf("Reporting pair failure to Mission "+
592+
m.log.Debugf("Reporting pair failure to Mission "+
585593
"Control: pair=%v, amt=%v",
586594
pair, pairResult.amt)
587595
}

0 commit comments

Comments
 (0)