From 1a9b7a6fc8c710e37ad02911375e3c33fc64dce8 Mon Sep 17 00:00:00 2001 From: Teodora Sechkova Date: Wed, 29 Jul 2020 18:01:20 +0300 Subject: [PATCH 1/2] Add NullHandler() to the top-level logger Adding a do-nothing handler to the top-level 'tuf' logger in case no other handlers exist (in tests for example). Signed-off-by: Teodora Sechkova --- tuf/log.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tuf/log.py b/tuf/log.py index 9d3612ab36..6a17a18710 100755 --- a/tuf/log.py +++ b/tuf/log.py @@ -118,6 +118,7 @@ # the standard pattern of logging.getLogger(__name__) logger = logging.getLogger('tuf') logger.setLevel(_DEFAULT_LOG_LEVEL) +logger.addHandler(logging.NullHandler()) # Set the built-in file handler. Messages will be logged to # 'settings.LOG_FILENAME', and only those messages with a log level of From 963ed79817d5cc8c6f25282b79a9c5210f4ee78d Mon Sep 17 00:00:00 2001 From: Teodora Sechkova Date: Wed, 29 Jul 2020 18:07:03 +0300 Subject: [PATCH 2/2] Replace logging.exception calls in Updater() Using logging.exception logs messages to the root logger and calls basicConfig() to add a console handler with a pre-defined format which breaks the current logging configuration. Replacing logging.exception with logger.exception which is the logger for the updater module. Signed-off-by: Teodora Sechkova --- tuf/client/updater.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tuf/client/updater.py b/tuf/client/updater.py index 2515ef66fb..cf09fe5b16 100755 --- a/tuf/client/updater.py +++ b/tuf/client/updater.py @@ -1151,12 +1151,12 @@ def neither_403_nor_404(mirror_error): # Otherwise, reraise the error, because it is not a simple HTTP # error. if neither_403_nor_404(mirror_error): - logging.exception('Misc error for root version '+str(next_version)) + logger.exception('Misc error for root version '+str(next_version)) raise else: # Calling this function should give us a detailed stack trace # including an HTTP error code, if any. - logging.exception('HTTP error for root version '+str(next_version)) + logger.exception('HTTP error for root version '+str(next_version)) # If we are here, then we ran into only 403 / 404 errors, which are # good reasons to suspect that the next root metadata file does not # exist.