diff --git a/reframe/core/logging.py b/reframe/core/logging.py index 697502435f..b36843c78f 100644 --- a/reframe/core/logging.py +++ b/reframe/core/logging.py @@ -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: @@ -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 diff --git a/reframe/frontend/cli.py b/reframe/frontend/cli.py index 7c3047a9eb..77c09b4337 100644 --- a/reframe/frontend/cli.py +++ b/reframe/frontend/cli.py @@ -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( @@ -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) diff --git a/unittests/test_cli.py b/unittests/test_cli.py index 21f9bb8537..cb644160a5 100644 --- a/unittests/test_cli.py +++ b/unittests/test_cli.py @@ -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)