|
8 | 8 |
|
9 | 9 | import argparse
|
10 | 10 | from collections import defaultdict, namedtuple
|
| 11 | +import glob |
11 | 12 | import heapq
|
12 | 13 | import itertools
|
13 | 14 | import os
|
@@ -76,9 +77,17 @@ def read_logs(tmp_dir):
|
76 | 77 | Delegates to generator function get_log_events() to provide individual log events
|
77 | 78 | for each of the input log files."""
|
78 | 79 |
|
| 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 | + |
79 | 88 | files = [("test", "%s/test_framework.log" % tmp_dir)]
|
80 | 89 | 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) |
82 | 91 | if not os.path.isfile(logfile):
|
83 | 92 | break
|
84 | 93 | files.append(("node%d" % i, logfile))
|
@@ -164,25 +173,26 @@ def get_log_events(source, logfile):
|
164 | 173 |
|
165 | 174 |
|
166 | 175 | 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"])) |
174 | 183 |
|
175 | 184 |
|
176 | 185 | 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('./')) |
184 | 193 | .get_template('combined_log_template.html')
|
185 | 194 | .render(title="Combined Logs from testcase", log_events=[event._asdict() for event in log_events]))
|
186 | 195 |
|
| 196 | + |
187 | 197 | if __name__ == '__main__':
|
188 | 198 | main()
|
0 commit comments