Skip to content

Commit

Permalink
Merge branch 'log-name' of 'https://github.com/jjmerchante/grimoirela…
Browse files Browse the repository at this point in the history
…b-sirmordred'

Merges #598
Closes #598
  • Loading branch information
sduenas authored Oct 11, 2023
2 parents 965fa44 + 53c577f commit d584781
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Log format updated with the Mordred project name
category: changed
author: Jose Javier Merchante <[email protected]>
issue: null
notes: >
Update the log format of SirMordred and MicroMordred to
include the name of the project.
7 changes: 4 additions & 3 deletions sirmordred/bin/sirmordred.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down
22 changes: 10 additions & 12 deletions sirmordred/utils/micro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d584781

Please sign in to comment.