Skip to content

Commit faf3683

Browse files
author
MarcoFalke
committed
test: Avoid hardcoding the chain name in combine_logs
1 parent fa8a1d7 commit faf3683

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

test/functional/combine_logs.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import argparse
1010
from collections import defaultdict, namedtuple
11+
import glob
1112
import heapq
1213
import itertools
1314
import os
@@ -76,9 +77,17 @@ def read_logs(tmp_dir):
7677
Delegates to generator function get_log_events() to provide individual log events
7778
for each of the input log files."""
7879

80+
# Find out what the folder is called that holds the debug.log file
81+
chain = glob.glob("{}/node0/*/debug.log".format(tmp_dir))
82+
if chain:
83+
chain = chain[0] # pick the first one if more than one chain was found (should never happen)
84+
chain = re.search('node0/(.+?)/debug\.log$', chain).group(1) # extract the chain name
85+
else:
86+
chain = 'regtest' # fallback to regtest (should only happen when none exists)
87+
7988
files = [("test", "%s/test_framework.log" % tmp_dir)]
8089
for i in itertools.count():
81-
logfile = "{}/node{}/regtest/debug.log".format(tmp_dir, i)
90+
logfile = "{}/node{}/{}/debug.log".format(tmp_dir, i, chain)
8291
if not os.path.isfile(logfile):
8392
break
8493
files.append(("node%d" % i, logfile))
@@ -164,25 +173,26 @@ def get_log_events(source, logfile):
164173

165174

166175
def print_logs_plain(log_events, colors):
167-
"""Renders the iterator of log events into text."""
168-
for event in log_events:
169-
lines = event.event.splitlines()
170-
print("{0} {1: <5} {2} {3}".format(colors[event.source.rstrip()], event.source, lines[0], colors["reset"]))
171-
if len(lines) > 1:
172-
for line in lines[1:]:
173-
print("{0}{1}{2}".format(colors[event.source.rstrip()], line, colors["reset"]))
176+
"""Renders the iterator of log events into text."""
177+
for event in log_events:
178+
lines = event.event.splitlines()
179+
print("{0} {1: <5} {2} {3}".format(colors[event.source.rstrip()], event.source, lines[0], colors["reset"]))
180+
if len(lines) > 1:
181+
for line in lines[1:]:
182+
print("{0}{1}{2}".format(colors[event.source.rstrip()], line, colors["reset"]))
174183

175184

176185
def print_logs_html(log_events):
177-
"""Renders the iterator of log events into html."""
178-
try:
179-
import jinja2
180-
except ImportError:
181-
print("jinja2 not found. Try `pip install jinja2`")
182-
sys.exit(1)
183-
print(jinja2.Environment(loader=jinja2.FileSystemLoader('./'))
186+
"""Renders the iterator of log events into html."""
187+
try:
188+
import jinja2
189+
except ImportError:
190+
print("jinja2 not found. Try `pip install jinja2`")
191+
sys.exit(1)
192+
print(jinja2.Environment(loader=jinja2.FileSystemLoader('./'))
184193
.get_template('combined_log_template.html')
185194
.render(title="Combined Logs from testcase", log_events=[event._asdict() for event in log_events]))
186195

196+
187197
if __name__ == '__main__':
188198
main()

0 commit comments

Comments
 (0)