From 2686492bfce69ec9a47e500c5433130d5d0f18d1 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 28 2020 15:51:48 +0000 Subject: [PATCH 1/2] Set up the loggers in the hooks Otherwise, we can configure all the loggers we want to log to a file or anything like this, the loggers won't be configured and thus all our configuration will be not so useful. Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/hooks/files/hookrunner b/pagure/hooks/files/hookrunner index e40e1e8..2d775ff 100755 --- a/pagure/hooks/files/hookrunner +++ b/pagure/hooks/files/hookrunner @@ -6,11 +6,11 @@ Authors: Patrick Uiterwijk - + Notes: If you've installed Pagure with a virtual environment, replace the interpreter path like this: - + #!/path/to/pagure_env/bin/python """ @@ -19,7 +19,7 @@ from __future__ import unicode_literals, absolute_import import os import sys - + # The following is only needed if you did not install pagure # as a python module (for example if you run it from a git clone). #sys.path.insert(0, '/path/to/pagure/') @@ -36,8 +36,10 @@ if "PAGURE_CONFIG" not in os.environ and os.path.exists( os.environ["PAGURE_CONFIG"] = "/etc/pagure/pagure.cfg" import pagure.lib +import pagure.utils from pagure.hooks import run_hook_file +pagure.utils.set_up_logging() hooktype = os.path.basename(sys.argv[0]) run_hook_file(hooktype) diff --git a/tests/__init__.py b/tests/__init__.py index 18e6ee2..b6253a5 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -115,6 +115,25 @@ REPOSPANNER_REGIONS = { 'push_cert': {'cert': '%(path)s/repospanner/pki/pagure.crt', 'key': '%(path)s/repospanner/pki/pagure.key'}} } +LOGGING = { + "version": 1, + "disable_existing_loggers": False, + "formatters": { + "standard": { + "format": "%%(asctime)s [%%(levelname)s] %%(name)s: %%(message)s" + }, + }, + "handlers": { + "console": { + "formatter": "standard", + "class": "logging.StreamHandler", + "stream": "ext://sys.stderr", + }, + }, + # The root logger configuration; this is a catch-all configuration + # that applies to all log messages not handled by a different logger + "root": {"level": "WARN", "handlers": ["console"]}, +} """ # The Celery docs warn against using task_always_eager: # http://docs.celeryproject.org/en/latest/userguide/testing.html From 02fde64a35da37708b50bc7fa2ff1570fc59685d Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 28 2020 15:51:48 +0000 Subject: [PATCH 2/2] Adjust the example configuration for logging to a file Use a TimedRotatingFileHandler instead of a plain FileHandler as the former allows to automatically rotate the file every day at a given time, thus avoiding the issue of the ever-growing log file. Signed-off-by: Pierre-Yves Chibon --- diff --git a/doc/configuration.rst b/doc/configuration.rst index 75b4203..efc385f 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -908,12 +908,17 @@ The default value is: "auth_handler": { "formatter": "standard", - "class": "logging.FileHandler", + "class": "logging.handlers.TimedRotatingFileHandler", "filename": "/var/log/pagure/pagure_auth.log", - } + "backupCount": 10, + "when": "midnight", + "utc": True, + }, - Beware if you do this that you will also likely want to enable logrotate - on the system. + This snippet will automatically make the logs rotate at midnight each day, + keep the logs for 10 days and use UTC as timezone for the logs. Depending on + how your pagure instance is set-up, you may have to tweak the filesystem + permissions on the folder and file so the rotation works properly. ITEM_PER_PAGE