Skip to content

Commit 9519a23

Browse files
authored
Merge pull request #9278 from starius/debuglevel-show-no-checks
config: fix "lnd --debuglevel show" command
2 parents 411ad1d + 64c660c commit 9519a23

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

config.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,18 @@ func LoadConfig(interceptor signal.Interceptor) (*Config, error) {
860860
func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser,
861861
flagParser *flags.Parser) (*Config, error) {
862862

863+
// Special show command to list supported subsystems and exit.
864+
if cfg.DebugLevel == "show" {
865+
subLogMgr := build.NewSubLoggerManager()
866+
867+
// Initialize logging at the default logging level.
868+
SetupLoggers(subLogMgr, interceptor)
869+
870+
fmt.Println("Supported subsystems",
871+
subLogMgr.SupportedSubsystems())
872+
os.Exit(0)
873+
}
874+
863875
// If the provided lnd directory is not the default, we'll modify the
864876
// path to all of the files and directories that will live within it.
865877
lndDir := CleanAndExpandPath(cfg.LndDir)
@@ -1249,7 +1261,7 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser,
12491261
// The target network must be provided, otherwise, we won't
12501262
// know how to initialize the daemon.
12511263
if numNets == 0 {
1252-
str := "either --bitcoin.mainnet, or bitcoin.testnet," +
1264+
str := "either --bitcoin.mainnet, or bitcoin.testnet, " +
12531265
"bitcoin.simnet, bitcoin.regtest or bitcoin.signet " +
12541266
"must be specified"
12551267

@@ -1408,13 +1420,6 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser,
14081420
// Initialize logging at the default logging level.
14091421
SetupLoggers(cfg.SubLogMgr, interceptor)
14101422

1411-
// Special show command to list supported subsystems and exit.
1412-
if cfg.DebugLevel == "show" {
1413-
fmt.Println("Supported subsystems",
1414-
cfg.SubLogMgr.SupportedSubsystems())
1415-
os.Exit(0)
1416-
}
1417-
14181423
if cfg.MaxLogFiles != 0 {
14191424
if cfg.LogConfig.File.MaxLogFiles !=
14201425
build.DefaultMaxLogFiles {

itest/config.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//go:build integration
2+
3+
package itest
4+
5+
import (
6+
"os/exec"
7+
8+
"github.com/lightningnetwork/lnd/lntest"
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
// testDebuglevelShow tests that "lnd --debuglevel=show" command works and
13+
// prints the list of supported subsystems.
14+
func testDebuglevelShow(ht *lntest.HarnessTest) {
15+
// We can't use ht.NewNode, because it adds more arguments to the
16+
// command line (e.g. flags configuring bitcoin backend), but we want to
17+
// make sure that "lnd --debuglevel=show" works without any other flags.
18+
lndBinary := getLndBinary(ht.T)
19+
cmd := exec.Command(lndBinary, "--debuglevel=show")
20+
stdoutStderrBytes, err := cmd.CombinedOutput()
21+
require.NoError(ht, err, "failed to run 'lnd --debuglevel=show'")
22+
23+
// Make sure that the output contains the list of supported subsystems
24+
// and that the list is not empty. We search PEER subsystem.
25+
stdoutStderr := string(stdoutStderrBytes)
26+
require.Contains(ht, stdoutStderr, "Supported subsystems")
27+
require.Contains(ht, stdoutStderr, "PEER")
28+
}

itest/list_on_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,4 +702,8 @@ var allTestCases = []*lntest.TestCase{
702702
Name: "send to route failed htlc timeout",
703703
TestFunc: testSendToRouteFailHTLCTimeout,
704704
},
705+
{
706+
Name: "debuglevel show",
707+
TestFunc: testDebuglevelShow,
708+
},
705709
}

0 commit comments

Comments
 (0)