From 2b8d6f0279e3435061a9140256ddb5b910b69cce Mon Sep 17 00:00:00 2001 From: Vitaly Gavensky Date: Wed, 15 May 2024 19:28:54 +0300 Subject: [PATCH] Fix 8 --- .../tests/exclude_list_tests.py | 6 +++--- .../ufm_sim_web_service/isolation_algo.py | 19 +++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/plugins/pdr_deterministic_plugin/tests/exclude_list_tests.py b/plugins/pdr_deterministic_plugin/tests/exclude_list_tests.py index cb96887cf..d87a13b58 100644 --- a/plugins/pdr_deterministic_plugin/tests/exclude_list_tests.py +++ b/plugins/pdr_deterministic_plugin/tests/exclude_list_tests.py @@ -24,10 +24,10 @@ def test_get_from_empty_exclude_list(): """ print("Test 5") - filename = os.path.basename(Constants.LOG_FILE) - lod_file = os.path.join(tempfile.gettempdir(), filename) + log_name = os.path.basename(Constants.LOG_FILE) + log_path = os.path.join(tempfile.gettempdir(), log_name) - logger = create_logger(lod_file) + logger = create_logger(log_path) exclude_list = ExcludeList(logger) items = exclude_list.items() assert not items diff --git a/plugins/pdr_deterministic_plugin/ufm_sim_web_service/isolation_algo.py b/plugins/pdr_deterministic_plugin/ufm_sim_web_service/isolation_algo.py index 58350b4f5..b5272c5d5 100644 --- a/plugins/pdr_deterministic_plugin/ufm_sim_web_service/isolation_algo.py +++ b/plugins/pdr_deterministic_plugin/ufm_sim_web_service/isolation_algo.py @@ -26,27 +26,26 @@ from utils.utils import Utils -def create_logger(file): +def create_logger(log_file): """ create a logger to put all the data of the server action :param file: name of the file :return: """ - format_str = "%(asctime)-15s UFM-PDR_deterministic-plugin-{0} Machine: {1} %(levelname)-7s: %(message)s".format(file,'localhost') - log_name = Constants.LOG_FILE - if not os.path.exists(log_name): - os.makedirs('/'.join(log_name.split('/')[:-1]), exist_ok=True) - logger = logging.getLogger(log_name) + format_str = "%(asctime)-15s UFM-PDR_deterministic-plugin-{0} Machine: {1} %(levelname)-7s: %(message)s".format(log_file,'localhost') + if not os.path.exists(log_file): + os.makedirs('/'.join(log_file.split('/')[:-1]), exist_ok=True) + logger = logging.getLogger(log_file) logging_level = logging.getLevelName(Constants.log_level) \ if isinstance(Constants.log_level, str) else Constants.log_level logging.basicConfig(format=format_str,level=logging_level) - rotateHandler = RotatingFileHandler(log_name,maxBytes=Constants.log_file_max_size, + rotate_handler = RotatingFileHandler(log_file,maxBytes=Constants.log_file_max_size, backupCount=Constants.log_file_backup_count) - rotateHandler.setLevel(Constants.log_level) - rotateHandler.setFormatter(logging.Formatter(format_str)) - logger.addHandler(rotateHandler) + rotate_handler.setLevel(Constants.log_level) + rotate_handler.setFormatter(logging.Formatter(format_str)) + logger.addHandler(rotate_handler) return logger