Changeset View
Changeset View
Standalone View
Standalone View
test/functional/combine_logs.py
Show All 31 Lines | def main(): | ||||
if args.color and os.name != 'posix': | if args.color and os.name != 'posix': | ||||
print("Color output requires posix terminal colors.") | print("Color output requires posix terminal colors.") | ||||
sys.exit(1) | sys.exit(1) | ||||
if args.html and args.color: | if args.html and args.color: | ||||
print("Only one out of --color or --html should be specified") | print("Only one out of --color or --html should be specified") | ||||
sys.exit(1) | sys.exit(1) | ||||
# There should only be one unknown argument - the path of the temporary test directory | # There should only be one unknown argument - the path of the temporary | ||||
# test directory | |||||
if len(unknown_args) != 1: | if len(unknown_args) != 1: | ||||
print("Unexpected arguments" + str(unknown_args)) | print("Unexpected arguments" + str(unknown_args)) | ||||
sys.exit(1) | sys.exit(1) | ||||
log_events = read_logs(unknown_args[0]) | log_events = read_logs(unknown_args[0]) | ||||
print_logs(log_events, color=args.color, html=args.html) | print_logs(log_events, color=args.color, html=args.html) | ||||
Show All 22 Lines | def get_log_events(source, logfile): | ||||
try: | try: | ||||
with open(logfile, 'r', encoding='utf-8') as infile: | with open(logfile, 'r', encoding='utf-8') as infile: | ||||
event = '' | event = '' | ||||
timestamp = '' | timestamp = '' | ||||
for line in infile: | for line in infile: | ||||
# skip blank lines | # skip blank lines | ||||
if line == '\n': | if line == '\n': | ||||
continue | continue | ||||
# if this line has a timestamp, it's the start of a new log event. | # if this line has a timestamp, it's the start of a new log | ||||
# event. | |||||
time_match = TIMESTAMP_PATTERN.match(line) | time_match = TIMESTAMP_PATTERN.match(line) | ||||
if time_match: | if time_match: | ||||
if event: | if event: | ||||
yield LogEvent(timestamp=timestamp, source=source, event=event.rstrip()) | yield LogEvent(timestamp=timestamp, source=source, event=event.rstrip()) | ||||
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 {} could not be opened. Continuing without it.".format( | print("File {} could not be opened. Continuing without it.".format( | ||||
logfile), file=sys.stderr) | logfile), file=sys.stderr) | ||||
Show All 30 Lines |