integration tests: add -logoutput flag that can be used to log output from the seed nodes to files.
This commit is contained in:
parent
906771ba16
commit
2e6800e1ed
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@ -53,6 +54,11 @@ var (
|
||||
defaultClientPort = 19556
|
||||
|
||||
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
|
||||
@ -187,6 +193,26 @@ func (l *lightningNode) Start(lndError chan error) error {
|
||||
var errb bytes.Buffer
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user