From a4b604d064eb66ee2ca061df0ca79bb682689317 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Aug 03 2020 19:53:00 +0000 Subject: Allow having a dedicated loggin configuration for the git hooks Pagure's logging can now be configured in ``LOGGING`` as before for both the web application as well as the git hooks. But if needed/desired, the git hooks can have a different logging configuration that will be specified in ``LOGGING_GIT_HOOKS``. If ``LOGGING_GIT_HOOKS`` is not specified (default) the ``LOGGING`` configuration will be used instead. Signed-off-by: Pierre-Yves Chibon --- diff --git a/doc/configuration.rst b/doc/configuration.rst index efc385f..735e378 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -800,6 +800,19 @@ Defaults to: Where ``{nonce}`` is dynamically set by pagure. +LOGGING_GIT_HOOKS +~~~~~~~~~~~~~~~~~ + +This configuration key allows to have a different logging configuration for the +web application and the git hooks. + +If un-specified (default), the logging configuration used by the git hooks will +be the same as the one for the web application (i.e.: defined in ``LOGGING`` here +below). + +Defaults to: ``None``. + + LOGGING ~~~~~~~ diff --git a/pagure/default_config.py b/pagure/default_config.py index 5ab85ff..045f270 100644 --- a/pagure/default_config.py +++ b/pagure/default_config.py @@ -444,6 +444,7 @@ STOMP_CERT_FILE = None STOMP_CREDS_PASSWORD = None STOMP_HIERARCHY = None + LOGGING = { "version": 1, "disable_existing_loggers": False, diff --git a/pagure/hooks/files/hookrunner b/pagure/hooks/files/hookrunner index 2d775ff..e1690d0 100755 --- a/pagure/hooks/files/hookrunner +++ b/pagure/hooks/files/hookrunner @@ -37,9 +37,12 @@ if "PAGURE_CONFIG" not in os.environ and os.path.exists( import pagure.lib import pagure.utils +from pagure.config import config as pagure_config from pagure.hooks import run_hook_file -pagure.utils.set_up_logging() +confkey = "LOGGING_GIT_HOOKS" if "LOGGING_GIT_HOOKS" in pagure_config else "LOGGING" + +pagure.utils.set_up_logging(configkey=confkey) hooktype = os.path.basename(sys.argv[0]) run_hook_file(hooktype) diff --git a/pagure/utils.py b/pagure/utils.py index fcf1b6b..24a0ce4 100644 --- a/pagure/utils.py +++ b/pagure/utils.py @@ -36,14 +36,14 @@ _log = logging.getLogger(__name__) LOGGER_SETUP = False -def set_up_logging(app=None, force=False): +def set_up_logging(app=None, force=False, configkey="LOGGING"): global LOGGER_SETUP if LOGGER_SETUP and not force: _log.info("logging already setup") return logging.basicConfig() - logging.config.dictConfig(pagure_config.get("LOGGING") or {"version": 1}) + logging.config.dictConfig(pagure_config.get(configkey) or {"version": 1}) LOGGER_SETUP = True