integration tests: add -logoutput flag that can be used to log output from the seed nodes to files.
This commit is contained in:
1 parent
906771ba16
commit
2e6800e1ed
1 file changed
+26
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@@ -53,6 +54,11 @@ var (
|
|||||||
defaultClientPort = 19556
|
defaultClientPort = 19556
|
||||||
|
|
||||||
harnessNetParams = &chaincfg.SimNetParams
|
harnessNetParams = &chaincfg.SimNetParams
|
||||||
|
|
||||||
|
// logOutput is a flag that can be set to append the output from the
|
||||||
|
// seed nodes to log files.
|
||||||
|
logOutput = flag.Bool("logoutput", false,
|
||||||
|
"log output from node n to file outputn.log")
|
||||||
)
|
)
|
||||||
|
|
||||||
// generateListeningPorts returns two strings representing ports to listen on
|
// generateListeningPorts returns two strings representing ports to listen on
|
||||||
@@ -187,6 +193,26 @@ func (l *lightningNode) Start(lndError chan error) error {
|
|||||||
var errb bytes.Buffer
|
var errb bytes.Buffer
|
||||||
l.cmd.Stderr = &errb
|
l.cmd.Stderr = &errb
|
||||||
|
|
||||||
|
// If the logoutput flag is passed, redirect output from the nodes to
|
||||||
|
// log files.
|
||||||
|
if *logOutput {
|
||||||
|
logFile := fmt.Sprintf("output%d.log", l.nodeID)
|
||||||
|
|
||||||
|
// Create file if not exists, otherwise append.
|
||||||
|
file, err := os.OpenFile(logFile,
|
||||||
|
os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pass node's stderr to both errb and the file.
|
||||||
|
w := io.MultiWriter(&errb, file)
|
||||||
|
l.cmd.Stderr = w
|
||||||
|
|
||||||
|
// Pass the node's stdout only to the file.
|
||||||
|
l.cmd.Stdout = file
|
||||||
|
}
|
||||||
|
|
||||||
if err := l.cmd.Start(); err != nil {
|
if err := l.cmd.Start(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user