mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-04 09:48:19 +01:00
Merge pull request #5354 from ErikEk/itest-include-btcd-backend-rotation-logs
itest: include compressed btcd backend logs from logrotate
This commit is contained in:
commit
648374ec2a
3 changed files with 57 additions and 20 deletions
|
@ -161,6 +161,11 @@ you.
|
|||
when encoding/decoding messages. Such that most of the heap escapes are fixed,
|
||||
resulting in less memory being used when running `lnd`.
|
||||
|
||||
## Log system
|
||||
|
||||
* [Save compressed log files from logrorate during
|
||||
itest](https://github.com/lightningnetwork/lnd/pull/5354).
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
A bug has been fixed that would cause `lnd` to [try to bootstrap using the
|
||||
|
|
|
@ -6,7 +6,9 @@ import (
|
|||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/btcsuite/btcd/btcjson"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
|
@ -118,15 +120,30 @@ func NewBackend(miner string, netParams *chaincfg.Params) (
|
|||
}
|
||||
|
||||
// After shutting down the chain backend, we'll make a copy of
|
||||
// the log file before deleting the temporary log dir.
|
||||
logFile := baseLogDir + "/" + netParams.Name + "/btcd.log"
|
||||
logDestination := fmt.Sprintf(
|
||||
"%s/output_btcd_chainbackend.log", GetLogDir(),
|
||||
)
|
||||
err := CopyFile(logDestination, logFile)
|
||||
// the log files, including any compressed log files from
|
||||
// logrorate, before deleting the temporary log dir.
|
||||
logDir := fmt.Sprintf("%s/%s", baseLogDir, netParams.Name)
|
||||
files, err := ioutil.ReadDir(logDir)
|
||||
if err != nil {
|
||||
errStr += fmt.Sprintf("unable to copy file: %v\n", err)
|
||||
errStr += fmt.Sprintf(
|
||||
"unable to read log directory: %v\n", err,
|
||||
)
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
logFile := fmt.Sprintf("%s/%s", logDir, file.Name())
|
||||
newFilename := strings.Replace(
|
||||
file.Name(), "btcd.log", "output_btcd_chainbackend.log", 1,
|
||||
)
|
||||
logDestination := fmt.Sprintf(
|
||||
"%s/%s", GetLogDir(), newFilename,
|
||||
)
|
||||
err := CopyFile(logDestination, logFile)
|
||||
if err != nil {
|
||||
errStr += fmt.Sprintf("unable to copy file: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
if err = os.RemoveAll(baseLogDir); err != nil {
|
||||
errStr += fmt.Sprintf(
|
||||
"cannot remove dir %s: %v\n", baseLogDir, err,
|
||||
|
|
|
@ -445,10 +445,11 @@ func newNode(cfg NodeConfig) (*HarnessNode, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
// NewMiner creates a new miner using btcd backend. The logDir specifies the
|
||||
// miner node's log dir. When tests finished, during clean up, its logs are
|
||||
// copied to a file specified as logFilename.
|
||||
func NewMiner(logDir, logFilename string, netParams *chaincfg.Params,
|
||||
// NewMiner creates a new miner using btcd backend. The baseLogDir specifies
|
||||
// the miner node's log dir. When tests are finished, during clean up, its log
|
||||
// files, including any compressed log files from logrotate, are copied to
|
||||
// logDir as logFilename.
|
||||
func NewMiner(baseLogDir, logFilename string, netParams *chaincfg.Params,
|
||||
handler *rpcclient.NotificationHandlers,
|
||||
btcdBinary string) (*rpctest.Harness, func() error, error) {
|
||||
|
||||
|
@ -458,7 +459,7 @@ func NewMiner(logDir, logFilename string, netParams *chaincfg.Params,
|
|||
"--nowinservice",
|
||||
"--nobanning",
|
||||
"--debuglevel=debug",
|
||||
"--logdir=" + logDir,
|
||||
"--logdir=" + baseLogDir,
|
||||
"--trickleinterval=100ms",
|
||||
}
|
||||
|
||||
|
@ -476,18 +477,32 @@ func NewMiner(logDir, logFilename string, netParams *chaincfg.Params,
|
|||
)
|
||||
}
|
||||
|
||||
// After shutting down the miner, we'll make a copy of the log
|
||||
// file before deleting the temporary log dir.
|
||||
logFile := fmt.Sprintf("%s/%s/btcd.log", logDir, netParams.Name)
|
||||
copyPath := fmt.Sprintf("%s/../%s", logDir, logFilename)
|
||||
err := CopyFile(filepath.Clean(copyPath), logFile)
|
||||
// After shutting down the miner, we'll make a copy of
|
||||
// the log files before deleting the temporary log dir.
|
||||
logDir := fmt.Sprintf("%s/%s", baseLogDir, netParams.Name)
|
||||
files, err := ioutil.ReadDir(logDir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to copy file: %v", err)
|
||||
return fmt.Errorf("unable to read log directory: %v", err)
|
||||
}
|
||||
|
||||
if err = os.RemoveAll(logDir); err != nil {
|
||||
for _, file := range files {
|
||||
logFile := fmt.Sprintf(
|
||||
"%s/%s", logDir, file.Name(),
|
||||
)
|
||||
newFilename := strings.Replace(file.Name(), "btcd.log", logFilename, 1)
|
||||
copyPath := fmt.Sprintf(
|
||||
"%s/../%s", baseLogDir, newFilename,
|
||||
)
|
||||
|
||||
err := CopyFile(filepath.Clean(copyPath), logFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to copy file: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if err = os.RemoveAll(baseLogDir); err != nil {
|
||||
return fmt.Errorf(
|
||||
"cannot remove dir %s: %v", logDir, err,
|
||||
"cannot remove dir %s: %v", baseLogDir, err,
|
||||
)
|
||||
}
|
||||
return nil
|
||||
|
|
Loading…
Add table
Reference in a new issue