From c9da516f7d145e7b1726f30fb500bffcad34985f Mon Sep 17 00:00:00 2001 From: Brandon Rodriguez <brodriguez8774@gmail.com> Date: Fri, 15 Nov 2019 22:15:52 -0500 Subject: [PATCH] Correct a few minor bugs in reworked logging --- resources/logging.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/resources/logging.py b/resources/logging.py index 3dfe0a7..e0b2ac5 100644 --- a/resources/logging.py +++ b/resources/logging.py @@ -14,8 +14,9 @@ Note: Standard log priority is "NOTSET" > "DEBUG" > "INFO" > "WARNING" > "ERROR" import logging.config, os -# Statement to help library determine how to run logging. +# Statements to help library determine how to run logging. graph_library_logger = True +first_logging_call = True def get_logger(caller): @@ -25,8 +26,9 @@ def get_logger(caller): :param caller: __name__ attribute of caller. :return: Instance of logger, associated with caller's __name__. """ - # Initialize logger. - _initialize_logger_settings() + # Initialize logger. We should only have to initialize it once per project. + if first_logging_call: + _initialize_logger_settings() # Return logger instance, using passed name. return logging.getLogger(caller) @@ -49,9 +51,14 @@ def _initialize_logger_settings(debug=False): # Load dictionary of settings into logger. logging.config.dictConfig(_create_logging_dict(log_dir)) + # Now that logging has been initialized once, we don't need to call this function again for the duration of program + # runtime. Set "first_logging_call" variable accordingly. + global first_logging_call + first_logging_call = False + # Optionally test that logging is working as expected. if debug: - logger = get_logger(__name__) + logger = logging.getLogger(__name__) logger.info('Logging initialized.') logger.debug('Logging directory: {0}'.format(log_dir)) -- GitLab