From dd7811c4921bc0b2f71845f2649238dc3145e777 Mon Sep 17 00:00:00 2001 From: Alex Zorin Date: Wed, 12 May 2021 07:59:17 +1000 Subject: [PATCH] print logfile rather than logdir in exit handler --- certbot/certbot/_internal/log.py | 5 ++--- certbot/tests/log_test.py | 7 ++++--- tests/lock_test.py | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/certbot/certbot/_internal/log.py b/certbot/certbot/_internal/log.py index 700f9e9f4..3399749ad 100644 --- a/certbot/certbot/_internal/log.py +++ b/certbot/certbot/_internal/log.py @@ -98,7 +98,6 @@ def post_arg_parse_setup(config): """ file_handler, file_path = setup_log_file_handler( config, 'letsencrypt.log', FILE_FMT) - logs_dir = os.path.dirname(file_path) root_logger = logging.getLogger() memory_handler = stderr_handler = None @@ -131,7 +130,7 @@ def post_arg_parse_setup(config): sys.excepthook = functools.partial( post_arg_parse_except_hook, - debug=config.debug, quiet=config.quiet, log_path=logs_dir) + debug=config.debug, quiet=config.quiet, log_path=file_path) def setup_log_file_handler(config, logfile, fmt): @@ -377,6 +376,6 @@ def exit_with_advice(log_path: str): if os.path.isdir(log_path): msg += f'logfiles in {log_path} ' else: - msg += f"logfile '{log_path}' " + msg += f"logfile {log_path} " msg += 'or re-run Certbot with -v for more details.' sys.exit(msg) diff --git a/certbot/tests/log_test.py b/certbot/tests/log_test.py index eaf023893..06ac6d14a 100644 --- a/certbot/tests/log_test.py +++ b/certbot/tests/log_test.py @@ -101,16 +101,17 @@ class PostArgParseSetupTest(test_util.ConfigTestCase): mock_sys.version_info = sys.version_info self._call(self.config) + log_path = os.path.join(self.config.logs_dir, 'letsencrypt.log') + self.root_logger.removeHandler.assert_called_once_with( self.memory_handler) self.assertTrue(self.root_logger.addHandler.called) - self.assertTrue(os.path.exists(os.path.join( - self.config.logs_dir, 'letsencrypt.log'))) + self.assertTrue(os.path.exists(log_path)) self.assertFalse(os.path.exists(self.temp_path)) mock_sys.excepthook(1, 2, 3) mock_except_hook.assert_called_once_with( 1, 2, 3, debug=self.config.debug, - quiet=self.config.quiet, log_path=self.config.logs_dir) + quiet=self.config.quiet, log_path=log_path) level = self.stream_handler.level if self.config.quiet: diff --git a/tests/lock_test.py b/tests/lock_test.py index 5035fcb37..c4ec2a99e 100644 --- a/tests/lock_test.py +++ b/tests/lock_test.py @@ -214,7 +214,7 @@ def check_error(command, dir_path): report_failure("Certbot didn't exit with a nonzero status!", out, err) # this regex looks weird in order to deal with a text change between HEAD and -oldest - match = re.search("ee the logfile '(.*)' ", err) + match = re.search("ee the logfile '?(.*?)'? ", err) if match is not None: # Get error output from more verbose logfile with open(match.group(1)) as f: