Skip to content

Commit ee9e6e7

Browse files
committed
Merge #14051: [Tests] Make combine_logs.py handle multi-line logs
16e288a test padding non micro timestamps (John Newbery) 995dd89 [Tests] Make combine_logs.py handle multi-line logs (John Newbery) Pull request description: combine_logs.py currently inserts additional newlines into multi-line log messages, and doesn't color them properly. Fix both of those. Tree-SHA512: dbe2f3ecc7cfbc95ee4350e648d127538c79cb6555257d4aeec12fe3d159366742b68e90e620c8ed7219a44b973395c7e5929ba374fae115fbee25560db645f6
2 parents 0df9b0a + 16e288a commit ee9e6e7

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

test/functional/combine_logs.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import sys
1414

1515
# Matches on the date format at the start of the log event
16-
TIMESTAMP_PATTERN = re.compile(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6}Z")
16+
TIMESTAMP_PATTERN = re.compile(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{6})?Z")
1717

1818
LogEvent = namedtuple('LogEvent', ['timestamp', 'source', 'event'])
1919

@@ -75,11 +75,17 @@ def get_log_events(source, logfile):
7575
if time_match:
7676
if event:
7777
yield LogEvent(timestamp=timestamp, source=source, event=event.rstrip())
78-
event = line
7978
timestamp = time_match.group()
79+
if time_match.group(1) is None:
80+
# timestamp does not have microseconds. Add zeroes.
81+
timestamp_micro = timestamp.replace("Z", ".000000Z")
82+
line = line.replace(timestamp, timestamp_micro)
83+
timestamp = timestamp_micro
84+
event = line
8085
# if it doesn't have a timestamp, it's a continuation line of the previous log.
8186
else:
82-
event += "\n" + line
87+
# Add the line. Prefix with space equivalent to the source + timestamp so log lines are aligned
88+
event += " " + line
8389
# Flush the final event
8490
yield LogEvent(timestamp=timestamp, source=source, event=event.rstrip())
8591
except FileNotFoundError:
@@ -98,7 +104,11 @@ def print_logs(log_events, color=False, html=False):
98104
colors["reset"] = "\033[0m" # Reset font color
99105

100106
for event in log_events:
101-
print("{0} {1: <5} {2} {3}".format(colors[event.source.rstrip()], event.source, event.event, colors["reset"]))
107+
lines = event.event.splitlines()
108+
print("{0} {1: <5} {2} {3}".format(colors[event.source.rstrip()], event.source, lines[0], colors["reset"]))
109+
if len(lines) > 1:
110+
for line in lines[1:]:
111+
print("{0}{1}{2}".format(colors[event.source.rstrip()], line, colors["reset"]))
102112

103113
else:
104114
try:

0 commit comments

Comments
 (0)