From 53c577fe7a3fc7b88637ceab51b40a505ecdfb4c Mon Sep 17 00:00:00 2001 From: Jose Javier Merchante Date: Wed, 11 Oct 2023 14:06:41 +0200 Subject: [PATCH] Log format updated with the Mordred project name This commits updates the logs for sirmordred and micromordred executions. It includes the name of the modred project in the logs. Signed-off-by: Jose Javier Merchante --- ...-updated-with-the-mordred-project-name.yml | 8 +++++++ sirmordred/bin/sirmordred.py | 7 +++--- sirmordred/utils/micro.py | 22 +++++++++---------- 3 files changed, 22 insertions(+), 15 deletions(-) create mode 100644 releases/unreleased/log-format-updated-with-the-mordred-project-name.yml diff --git a/releases/unreleased/log-format-updated-with-the-mordred-project-name.yml b/releases/unreleased/log-format-updated-with-the-mordred-project-name.yml new file mode 100644 index 00000000..aa345cda --- /dev/null +++ b/releases/unreleased/log-format-updated-with-the-mordred-project-name.yml @@ -0,0 +1,8 @@ +--- +title: Log format updated with the Mordred project name +category: changed +author: Jose Javier Merchante +issue: null +notes: > + Update the log format of SirMordred and MicroMordred to + include the name of the project. diff --git a/sirmordred/bin/sirmordred.py b/sirmordred/bin/sirmordred.py index daeadaae..399f680b 100755 --- a/sirmordred/bin/sirmordred.py +++ b/sirmordred/bin/sirmordred.py @@ -62,7 +62,8 @@ def main(): config_dict = config.get_conf() logs_dir = config_dict['general'].get('logs_dir', None) debug_mode = config_dict['general']['debug'] - logger = setup_logs(logs_dir, debug_mode) + short_name = config_dict['general']['short_name'] + logger = setup_logs(logs_dir, debug_mode, short_name) except RuntimeError as error: print("Error while consuming configuration: {}".format(error)) return 1 @@ -78,7 +79,7 @@ def main(): SirMordred(config).start() -def setup_logs(logs_dir, debug_mode): +def setup_logs(logs_dir, debug_mode, short_name): if debug_mode: logging_mode = logging.DEBUG @@ -89,7 +90,7 @@ def setup_logs(logs_dir, debug_mode): logger.setLevel(logging_mode) # create formatter and add it to the handlers - formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') + formatter = logging.Formatter(f'%(asctime)s - {short_name} - %(name)s - %(levelname)s - %(message)s') # create file handler if logs_dir: diff --git a/sirmordred/utils/micro.py b/sirmordred/utils/micro.py index 4c28293b..87a4d680 100644 --- a/sirmordred/utils/micro.py +++ b/sirmordred/utils/micro.py @@ -34,26 +34,26 @@ from sirmordred.task_panels import TaskPanels, TaskPanelsMenu from sirmordred.task_projects import TaskProjects -DEBUG_LOG_FORMAT = "[%(asctime)s - %(name)s - %(levelname)s] - %(message)s" -INFO_LOG_FORMAT = "%(asctime)s %(message)s" COLOR_LOG_FORMAT_SUFFIX = "\033[1m %(log_color)s " LOG_COLORS = {'DEBUG': 'white', 'INFO': 'cyan', 'WARNING': 'yellow', 'ERROR': 'red', 'CRITICAL': 'red,bg_white'} def main(): args = get_params() - config_logging(args.debug, args.logs_dir) - micro_mordred(args.cfg_path, args.backend_sections, + config = Config(args.cfg_path) + short_name = config['general']['short_name'] + config_logging(args.debug, args.logs_dir, short_name) + micro_mordred(config, args.backend_sections, args.repos_to_check, args.raw, args.identities_merge, args.enrich, args.panels) -def micro_mordred(cfg_path, backend_sections, repos_to_check, raw, identities_merge, enrich, panels): - """Execute the Mordred tasks using the configuration file (`cfg_path`). +def micro_mordred(config, backend_sections, repos_to_check, raw, identities_merge, enrich, panels): + """Execute the Mordred tasks using the configuration file. - :param cfg_path: the path of a Mordred configuration file + :param config: Mordred configuration file :param backend_sections: the backend sections where the raw/enrich/identities phases will be executed :param repos_to_check: process a repository only if it is in this list, or `None` for all repos :param raw: if true, it activates the collection of raw data @@ -62,8 +62,6 @@ def micro_mordred(cfg_path, backend_sections, repos_to_check, raw, identities_me :param panels: if true, it activates the upload of all panels declared in the configuration file """ - config = Config(cfg_path) - if raw: for backend in backend_sections: get_raw(config, backend, repos_to_check) @@ -145,14 +143,14 @@ def get_panels(config): logging.info("Panels creation finished!") -def config_logging(debug, logs_dir): +def config_logging(debug, logs_dir, short_name): """Config logging level output output""" if debug: - fmt = DEBUG_LOG_FORMAT + fmt = f"[%(asctime)s - {short_name} - %(name)s - %(levelname)s] - %(message)s" logging_mode = logging.DEBUG else: - fmt = INFO_LOG_FORMAT + fmt = f"%(asctime)s - {short_name} - %(message)s" logging_mode = logging.INFO # Setting the color scheme and level into the root logger