Skip to content

Commit 7a1ec4f

Browse files
Totktonadaylobankov
authored andcommitted
Prettify messages about log files
The ideas behind the change: * The log is sometimes from a tarantool instance, but a luatest based test may print logs from another process to stderr. Use more general term 'log' to don't confuse anyone. * Replace term 'instance' with 'test-run server' due to the same reasons. * Make zero size and no file situations more explicit. * Catch and report 'no logfile property' situation (shouldn't occur, but was semi-handled by this code previously for some reason). * Reduce code reusability for the sake of readability and to ease future modifications.
1 parent e65a5f8 commit 7a1ec4f

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

lib/server.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,31 @@ def stop(self, silent=True):
143143
def restart(self):
144144
pass
145145

146-
def print_log(self, lines=None):
147-
msg = ('\n{prefix} of Tarantool Log file [Instance "{instance}"]' +
148-
'[{logfile}]:\n').format(
149-
prefix="Last {0} lines".format(lines) if lines else "Output",
150-
instance=self.name,
151-
logfile=self.logfile or 'null')
152-
color_stdout(msg, schema='error')
153-
if os.path.exists(self.logfile):
154-
print_tail_n(self.logfile, lines)
146+
def print_log(self, num_lines=None):
147+
""" Show information from the given log file.
148+
"""
149+
prefix = '\n[test-run server "{instance}"] '.format(instance=self.name)
150+
if not self.logfile:
151+
msg = 'No log file is set (internal test-run error)\n'
152+
color_stdout(prefix + msg, schema='error')
153+
elif not os.path.exists(self.logfile):
154+
fmt_str = 'The log file {logfile} does not exist\n'
155+
msg = fmt_str.format(logfile=self.logfile)
156+
color_stdout(prefix + msg, schema='error')
157+
elif os.path.getsize(self.logfile) == 0:
158+
fmt_str = 'The log file {logfile} has zero size\n'
159+
msg = fmt_str.format(logfile=self.logfile)
160+
color_stdout(prefix + msg, schema='error')
161+
elif num_lines:
162+
fmt_str = 'Last {num_lines} lines of the log file {logfile}:\n'
163+
msg = fmt_str.format(logfile=self.logfile, num_lines=num_lines)
164+
color_stdout(prefix + msg, schema='error')
165+
print_tail_n(self.logfile, num_lines)
155166
else:
156-
color_stdout(" Can't find log:\n", schema='error')
167+
fmt_str = 'The log file {logfile}:\n'
168+
msg = fmt_str.format(logfile=self.logfile)
169+
color_stdout(msg, schema='error')
170+
print_tail_n(self.logfile, num_lines)
157171

158172
@staticmethod
159173
def exclude_tests(test_names, exclude_patterns):

0 commit comments

Comments
 (0)