Changeset View
Changeset View
Standalone View
Standalone View
test/functional/combine_logs.py
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
def read_logs(tmp_dir): | def read_logs(tmp_dir): | ||||
"""Reads log files. | """Reads log files. | ||||
Delegates to generator function get_log_events() to provide individual log events | Delegates to generator function get_log_events() to provide individual log events | ||||
for each of the input log files.""" | for each of the input log files.""" | ||||
files = [("test", "%s/test_framework.log" % tmp_dir)] | files = [("test", "{}/test_framework.log".format(tmp_dir))] | ||||
for i in itertools.count(): | for i in itertools.count(): | ||||
logfile = "{}/node{}/regtest/debug.log".format(tmp_dir, i) | logfile = "{}/node{}/regtest/debug.log".format(tmp_dir, i) | ||||
if not os.path.isfile(logfile): | if not os.path.isfile(logfile): | ||||
break | break | ||||
files.append(("node%d" % i, logfile)) | files.append(("node{}".format(i), logfile)) | ||||
return heapq.merge(*[get_log_events(source, f) for source, f in files]) | return heapq.merge(*[get_log_events(source, f) for source, f in files]) | ||||
def get_log_events(source, logfile): | def get_log_events(source, logfile): | ||||
"""Generator function that returns individual log events. | """Generator function that returns individual log events. | ||||
Log events may be split over multiple lines. We use the timestamp | Log events may be split over multiple lines. We use the timestamp | ||||
Show All 14 Lines | try: | ||||
event = line | event = line | ||||
timestamp = time_match.group() | timestamp = time_match.group() | ||||
# if it doesn't have a timestamp, it's a continuation line of the previous log. | # if it doesn't have a timestamp, it's a continuation line of the previous log. | ||||
else: | else: | ||||
event += "\n" + line | event += "\n" + line | ||||
# Flush the final event | # Flush the final event | ||||
yield LogEvent(timestamp=timestamp, source=source, event=event.rstrip()) | yield LogEvent(timestamp=timestamp, source=source, event=event.rstrip()) | ||||
except FileNotFoundError: | except FileNotFoundError: | ||||
print("File %s could not be opened. Continuing without it." % | print("File {} could not be opened. Continuing without it.".format(logfile), file=sys.stderr) | ||||
logfile, file=sys.stderr) | |||||
def print_logs(log_events, color=False, html=False): | def print_logs(log_events, color=False, html=False): | ||||
"""Renders the iterator of log events into text or html.""" | """Renders the iterator of log events into text or html.""" | ||||
if not html: | if not html: | ||||
colors = defaultdict(lambda: '') | colors = defaultdict(lambda: '') | ||||
if color: | if color: | ||||
colors["test"] = "\033[0;36m" # CYAN | colors["test"] = "\033[0;36m" # CYAN | ||||
Show All 23 Lines |