Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions reframe/core/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,14 @@ def setLevel(self, level):
if self.logger:
super().setLevel(level)

@property
def std_stream_handlers(self):
if self.logger:
return [h for h in self.logger.handlers
if h.stream == sys.stdout or h.stream == sys.stderr]
else:
return []

def _update_check_extras(self):
"""Return a dictionary with all the check-specific information."""
if self.check is None:
Expand Down Expand Up @@ -431,6 +439,18 @@ def error(self, message, *args, **kwargs):

super().error(message, *args, **kwargs)

def inc_verbosity(self, num_steps):
"""Convenience function for increasing the verbosity
of the logger step-wise."""
log_levels = sorted(_log_level_names.keys())[1:]
for h in self.std_stream_handlers:
level_idx = log_levels.index(h.level)
if level_idx - num_steps < 0:
new_level = log_levels[0]
else:
new_level = log_levels[level_idx - num_steps]

h.setLevel(new_level)


# A logger that doesn't log anything
Expand Down
5 changes: 5 additions & 0 deletions reframe/frontend/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ def main():
'--save-log-files', action='store_true', default=False,
help='Copy the log file from the work dir to the output dir at the '
'end of the program')
output_options.add_argument(
'--verbose', '-v', action='count', default=0,
help='Increase verbosity level of output')

# Check discovery options
locate_options.add_argument(
Expand Down Expand Up @@ -262,6 +265,8 @@ def main():
# Setup printer
printer = PrettyPrinter()
printer.colorize = options.colorize
if options.verbose:
printer.inc_verbosity(options.verbose)

try:
runtime.init_runtime(settings.site_configuration, options.system)
Expand Down
10 changes: 10 additions & 0 deletions unittests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,13 @@ def test_show_env_config_unknown_env(self):
self.assertNotIn('Traceback', stdout)
self.assertNotIn('Traceback', stderr)
self.assertEqual(1, returncode)

def test_verbosity(self):
self.more_options = ['-vvvvv']
self.system = 'testsys'
self.action = 'list'
returncode, stdout, stderr = self._run_reframe()
self.assertNotEqual('', stdout)
self.assertNotIn('Traceback', stdout)
self.assertNotIn('Traceback', stderr)
self.assertEqual(0, returncode)