Skip to content

Commit 168d1cb

Browse files
committed
root: allow disabling log file
1 parent d7e0340 commit 168d1cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+203
-152
lines changed

cmd/chantools/root.go

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,13 @@ const (
4747
)
4848

4949
var (
50-
Testnet bool
51-
Regtest bool
52-
Signet bool
50+
Testnet bool
51+
Regtest bool
52+
Signet bool
53+
NoLogFile bool
54+
55+
log btclog.Logger
5356

54-
logWriter = build.NewRotatingLogWriter()
55-
subLogMgr = build.NewSubLoggerManager(build.NewDefaultLogHandlers(
56-
build.DefaultLogConfig(), logWriter,
57-
)...)
58-
log = build.NewSubLogger("CHAN", genSubLogger(subLogMgr))
5957
chainParams = &chaincfg.MainNetParams
6058
)
6159

@@ -103,6 +101,11 @@ func main() {
103101
&Signet, "signet", "s", false, "Indicates if the public "+
104102
"signet parameters should be used",
105103
)
104+
rootCmd.PersistentFlags().BoolVar(
105+
&NoLogFile, "nologfile", false, "If set, no log file "+
106+
"will be created. This is useful for testing purposes "+
107+
"where we don't want to create a log file.",
108+
)
106109

107110
rootCmd.AddCommand(
108111
newChanBackupCommand(),
@@ -328,28 +331,34 @@ func readInput(input string) ([]byte, error) {
328331
}
329332

330333
func setupLogging() {
331-
setSubLogger("CHAN", log)
332-
addSubLogger("CHDB", channeldb.UseLogger)
333-
addSubLogger("BCKP", chanbackup.UseLogger)
334-
addSubLogger("PEER", peer.UseLogger)
335-
336-
err := logWriter.InitLogRotator(
337-
&build.FileLoggerConfig{
338-
Compressor: build.Gzip,
339-
MaxLogFiles: 3,
340-
MaxLogFileSize: 10,
341-
},
342-
"./results/chantools.log",
343-
)
344-
if err != nil {
345-
panic(err)
346-
}
347-
334+
logWriter := build.NewRotatingLogWriter()
348335
subLogMgr := build.NewSubLoggerManager(build.NewDefaultLogHandlers(
349336
build.DefaultLogConfig(), logWriter,
350337
)...)
351338

352-
err = build.ParseAndSetDebugLevels("debug", subLogMgr)
339+
log = build.NewSubLogger("CHAN", genSubLogger(subLogMgr))
340+
log.SetLevel(btclog.LevelDebug)
341+
342+
setSubLogger(subLogMgr, "CHAN", log)
343+
addSubLogger(subLogMgr, "CHDB", channeldb.UseLogger)
344+
addSubLogger(subLogMgr, "BCKP", chanbackup.UseLogger)
345+
addSubLogger(subLogMgr, "PEER", peer.UseLogger)
346+
347+
if !NoLogFile {
348+
err := logWriter.InitLogRotator(
349+
&build.FileLoggerConfig{
350+
Compressor: build.Gzip,
351+
MaxLogFiles: 3,
352+
MaxLogFileSize: 10,
353+
},
354+
"./results/chantools.log",
355+
)
356+
if err != nil {
357+
panic(err)
358+
}
359+
}
360+
361+
err := build.ParseAndSetDebugLevels("debug", subLogMgr)
353362
if err != nil {
354363
panic(err)
355364
}
@@ -364,17 +373,19 @@ func genSubLogger(mgr *build.SubLoggerManager) func(string) btclog.Logger {
364373

365374
// addSubLogger is a helper method to conveniently create and register the
366375
// logger of one or more sub systems.
367-
func addSubLogger(subsystem string, useLoggers ...func(btclog.Logger)) {
376+
func addSubLogger(subLogMgr *build.SubLoggerManager, subsystem string,
377+
useLoggers ...func(btclog.Logger)) {
378+
368379
// Create and register just a single logger to prevent them from
369380
// overwriting each other internally.
370381
logger := build.NewSubLogger(subsystem, genSubLogger(subLogMgr))
371-
setSubLogger(subsystem, logger, useLoggers...)
382+
setSubLogger(subLogMgr, subsystem, logger, useLoggers...)
372383
}
373384

374385
// setSubLogger is a helper method to conveniently register the logger of a sub
375386
// system.
376-
func setSubLogger(subsystem string, logger btclog.Logger,
377-
useLoggers ...func(btclog.Logger)) {
387+
func setSubLogger(subLogMgr *build.SubLoggerManager, subsystem string,
388+
logger btclog.Logger, useLoggers ...func(btclog.Logger)) {
378389

379390
subLogMgr.RegisterSubLogger(subsystem, logger)
380391
for _, useLogger := range useLoggers {

doc/chantools.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ https://github.com/lightninglabs/chantools/.
1212
### Options
1313

1414
```
15-
-h, --help help for chantools
16-
-r, --regtest Indicates if regtest parameters should be used
17-
-s, --signet Indicates if the public signet parameters should be used
18-
-t, --testnet Indicates if testnet parameters should be used
15+
-h, --help help for chantools
16+
--nologfile If set, no log file will be created. This is useful for testing purposes where we don't want to create a log file.
17+
-r, --regtest Indicates if regtest parameters should be used
18+
-s, --signet Indicates if the public signet parameters should be used
19+
-t, --testnet Indicates if testnet parameters should be used
1920
```
2021

2122
### SEE ALSO

doc/chantools_chanbackup.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ chantools chanbackup \
3333
### Options inherited from parent commands
3434

3535
```
36-
-r, --regtest Indicates if regtest parameters should be used
37-
-s, --signet Indicates if the public signet parameters should be used
38-
-t, --testnet Indicates if testnet parameters should be used
36+
--nologfile If set, no log file will be created. This is useful for testing purposes where we don't want to create a log file.
37+
-r, --regtest Indicates if regtest parameters should be used
38+
-s, --signet Indicates if the public signet parameters should be used
39+
-t, --testnet Indicates if testnet parameters should be used
3940
```
4041

4142
### SEE ALSO

doc/chantools_closepoolaccount.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ chantools closepoolaccount \
4848
### Options inherited from parent commands
4949

5050
```
51-
-r, --regtest Indicates if regtest parameters should be used
52-
-s, --signet Indicates if the public signet parameters should be used
53-
-t, --testnet Indicates if testnet parameters should be used
51+
--nologfile If set, no log file will be created. This is useful for testing purposes where we don't want to create a log file.
52+
-r, --regtest Indicates if regtest parameters should be used
53+
-s, --signet Indicates if the public signet parameters should be used
54+
-t, --testnet Indicates if testnet parameters should be used
5455
```
5556

5657
### SEE ALSO

doc/chantools_compactdb.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ chantools compactdb \
3131
### Options inherited from parent commands
3232

3333
```
34-
-r, --regtest Indicates if regtest parameters should be used
35-
-s, --signet Indicates if the public signet parameters should be used
36-
-t, --testnet Indicates if testnet parameters should be used
34+
--nologfile If set, no log file will be created. This is useful for testing purposes where we don't want to create a log file.
35+
-r, --regtest Indicates if regtest parameters should be used
36+
-s, --signet Indicates if the public signet parameters should be used
37+
-t, --testnet Indicates if testnet parameters should be used
3738
```
3839

3940
### SEE ALSO

doc/chantools_createwallet.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ chantools createwallet \
3333
### Options inherited from parent commands
3434

3535
```
36-
-r, --regtest Indicates if regtest parameters should be used
37-
-s, --signet Indicates if the public signet parameters should be used
38-
-t, --testnet Indicates if testnet parameters should be used
36+
--nologfile If set, no log file will be created. This is useful for testing purposes where we don't want to create a log file.
37+
-r, --regtest Indicates if regtest parameters should be used
38+
-s, --signet Indicates if the public signet parameters should be used
39+
-t, --testnet Indicates if testnet parameters should be used
3940
```
4041

4142
### SEE ALSO

doc/chantools_deletepayments.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ chantools deletepayments --failedonly \
3434
### Options inherited from parent commands
3535

3636
```
37-
-r, --regtest Indicates if regtest parameters should be used
38-
-s, --signet Indicates if the public signet parameters should be used
39-
-t, --testnet Indicates if testnet parameters should be used
37+
--nologfile If set, no log file will be created. This is useful for testing purposes where we don't want to create a log file.
38+
-r, --regtest Indicates if regtest parameters should be used
39+
-s, --signet Indicates if the public signet parameters should be used
40+
-t, --testnet Indicates if testnet parameters should be used
4041
```
4142

4243
### SEE ALSO

doc/chantools_doublespendinputs.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ chantools doublespendinputs \
4040
### Options inherited from parent commands
4141

4242
```
43-
-r, --regtest Indicates if regtest parameters should be used
44-
-s, --signet Indicates if the public signet parameters should be used
45-
-t, --testnet Indicates if testnet parameters should be used
43+
--nologfile If set, no log file will be created. This is useful for testing purposes where we don't want to create a log file.
44+
-r, --regtest Indicates if regtest parameters should be used
45+
-s, --signet Indicates if the public signet parameters should be used
46+
-t, --testnet Indicates if testnet parameters should be used
4647
```
4748

4849
### SEE ALSO

doc/chantools_dropchannelgraph.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ chantools dropchannelgraph \
4444
### Options inherited from parent commands
4545

4646
```
47-
-r, --regtest Indicates if regtest parameters should be used
48-
-s, --signet Indicates if the public signet parameters should be used
49-
-t, --testnet Indicates if testnet parameters should be used
47+
--nologfile If set, no log file will be created. This is useful for testing purposes where we don't want to create a log file.
48+
-r, --regtest Indicates if regtest parameters should be used
49+
-s, --signet Indicates if the public signet parameters should be used
50+
-t, --testnet Indicates if testnet parameters should be used
5051
```
5152

5253
### SEE ALSO

doc/chantools_dropgraphzombies.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ chantools dropgraphzombies \
3535
### Options inherited from parent commands
3636

3737
```
38-
-r, --regtest Indicates if regtest parameters should be used
39-
-s, --signet Indicates if the public signet parameters should be used
40-
-t, --testnet Indicates if testnet parameters should be used
38+
--nologfile If set, no log file will be created. This is useful for testing purposes where we don't want to create a log file.
39+
-r, --regtest Indicates if regtest parameters should be used
40+
-s, --signet Indicates if the public signet parameters should be used
41+
-t, --testnet Indicates if testnet parameters should be used
4142
```
4243

4344
### SEE ALSO

0 commit comments

Comments
 (0)