Skip to content

Commit

Permalink
Enable logging to unified file
Browse files Browse the repository at this point in the history
If the test fails and there is a unified log file (`run.log` by default)
you'll see the following output:

 - [box-luatest/varbinary_test.lua, null]
  # logfile:         /tmp/t/log/031_box-luatest.log
  # reproduce file:  /tmp/t/reproduce/031_box-luatest.list.yaml
  # unified logfile: /tmp/t/031_box-luatest/run.log

Closes #427
  • Loading branch information
Oleg Chaplashkin committed Jun 6, 2024
1 parent 84ebae5 commit c99a874
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/luatest_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ def __init__(self, *args, **kwargs):
def execute(self, server):
"""Execute test by luatest command
Execute `luatest -c --no-clean --verbose <name>_test.lua --output tap`
command. Disable capture mode and deletion of the var directory.
Provide a verbose output in the tap format. Extend the command by
`--pattern <pattern>` if the corresponding option is provided.
Execute `luatest -c --no-clean -l <path> --verbose <name>_test.lua --output tap`
command. Disable capture mode and deletion of the var directory. Provide a verbose
output in the tap format. Extend the command by `--pattern <pattern>` if the
corresponding option is provided.
"""
server.current_test = self
script = os.path.join(os.path.basename(server.testdir), self.name)
Expand All @@ -51,6 +51,8 @@ def execute(self, server):
if Options().args.pattern:
for p in Options().args.pattern:
command.extend(['--pattern', p])
unified_logfile_path = os.path.join(server.vardir, 'run.log')
command.extend(['-l', unified_logfile_path])

# We start luatest from the project source directory, it
# is the usual way to use luatest.
Expand Down
10 changes: 10 additions & 0 deletions lib/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ def get_reproduce_file(worker_name):
return os.path.join(reproduce_dir, '%s.list.yaml' % worker_name)


def get_unified_logfile(worker_name):
# Unified logging is only for LuatestServer workers.
# It doesn't always guarantee a log file.
# If it doesn't exist, it will return None.
if 'luatest' in worker_name:
path = os.path.join(main_vardir(), worker_name, Options().args.log)
if os.path.isfile(path):
return path


def print_greetings():
# print information about tarantool
color_stdout('\n')
Expand Down
4 changes: 4 additions & 0 deletions listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from lib.worker import WorkerOutput
from lib.worker import WorkerTaskResult
from lib.worker import get_reproduce_file
from lib.worker import get_unified_logfile
from lib.utils import prefix_each_line
from lib.utils import safe_makedirs
from lib.utils import print_tail_n
Expand Down Expand Up @@ -167,6 +168,9 @@ def print_tasks_info(self, tasks):
color_stdout("---\n", schema='separator')
print_tail_n(reproduce_file_path)
color_stdout("...\n", schema='separator')
unified_logfile_path = get_unified_logfile(worker_name)
if unified_logfile_path:
color_stdout('# unified logfile: %s\n' % unified_logfile_path)

def print_statistics(self):
"""Print statistics and results of testing."""
Expand Down

0 comments on commit c99a874

Please sign in to comment.