Skip to content

Commit 995dd89

Browse files
committed
[Tests] Make combine_logs.py handle multi-line logs
combine_logs.py currently inserts additional newlines into multi-line log messages, and doesn't color them properly. Fix both of those.
1 parent 540bf8a commit 995dd89

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

test/functional/combine_logs.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ def get_log_events(source, logfile):
7979
timestamp = time_match.group()
8080
# if it doesn't have a timestamp, it's a continuation line of the previous log.
8181
else:
82-
event += "\n" + line
82+
# Add the line. Prefix with space equivalent to the source + timestamp so log lines are aligned
83+
event += " " + line
8384
# Flush the final event
8485
yield LogEvent(timestamp=timestamp, source=source, event=event.rstrip())
8586
except FileNotFoundError:
@@ -98,7 +99,11 @@ def print_logs(log_events, color=False, html=False):
9899
colors["reset"] = "\033[0m" # Reset font color
99100

100101
for event in log_events:
101-
print("{0} {1: <5} {2} {3}".format(colors[event.source.rstrip()], event.source, event.event, colors["reset"]))
102+
lines = event.event.splitlines()
103+
print("{0} {1: <5} {2} {3}".format(colors[event.source.rstrip()], event.source, lines[0], colors["reset"]))
104+
if len(lines) > 1:
105+
for line in lines[1:]:
106+
print("{0}{1}{2}".format(colors[event.source.rstrip()], line, colors["reset"]))
102107

103108
else:
104109
try:

0 commit comments

Comments
 (0)