From 55c0637b984a2b09f22a593b89043770ba4d066c Mon Sep 17 00:00:00 2001 From: Kevin Morris Date: Thu, 24 Jun 2021 18:38:24 -0700 Subject: [PATCH] add logging.config.fileConfig This resolves logging issues with alembic on aurweb.initdb in addition to adding more logging utilities for aurweb and tests in general. Developers should fetch a logger for their specific module via `logging.getLogger(__name__)`. Signed-off-by: Kevin Morris --- aurweb/asgi.py | 1 + aurweb/initdb.py | 1 + aurweb/logging.py | 11 +++++++++ logging.conf | 62 +++++++++++++++++++++++++++++++++++++++++++++++ test/setup.sh | 1 + 5 files changed, 76 insertions(+) create mode 100644 aurweb/logging.py create mode 100644 logging.conf diff --git a/aurweb/asgi.py b/aurweb/asgi.py index 6c4d457d..45638277 100644 --- a/aurweb/asgi.py +++ b/aurweb/asgi.py @@ -9,6 +9,7 @@ from starlette.middleware.authentication import AuthenticationMiddleware from starlette.middleware.sessions import SessionMiddleware import aurweb.config +import aurweb.logging from aurweb.auth import BasicAuthBackend from aurweb.db import get_engine diff --git a/aurweb/initdb.py b/aurweb/initdb.py index 46f079c0..9a063ba4 100644 --- a/aurweb/initdb.py +++ b/aurweb/initdb.py @@ -4,6 +4,7 @@ import alembic.command import alembic.config import aurweb.db +import aurweb.logging import aurweb.schema diff --git a/aurweb/logging.py b/aurweb/logging.py new file mode 100644 index 00000000..d0154634 --- /dev/null +++ b/aurweb/logging.py @@ -0,0 +1,11 @@ +import logging +import logging.config +import os + +import aurweb.config + +aurwebdir = aurweb.config.get("options", "aurwebdir") +config_path = os.path.join(aurwebdir, "logging.conf") + +logging.config.fileConfig(config_path, disable_existing_loggers=False) +logger = logging.getLogger(__name__) diff --git a/logging.conf b/logging.conf new file mode 100644 index 00000000..e0959916 --- /dev/null +++ b/logging.conf @@ -0,0 +1,62 @@ +[loggers] +keys=root,aurweb,test,uvicorn,hypercorn,alembic + +[handlers] +keys=simpleHandler,detailedHandler + +[formatters] +keys=simpleFormatter,detailedFormatter + +[logger_root] +level=INFO +handlers=simpleHandler + +[logger_aurweb] +level=DEBUG +handlers=detailedHandler +qualname=aurweb +propagate=0 + +[logger_test] +level=DEBUG +handlers=detailedHandler +qualname=test +propagate=0 + +[logger_uvicorn] +level=DEBUG +handlers=simpleHandler +qualname=uvicorn +propagate=0 + +[logger_hypercorn] +level=DEBUG +handlers=simpleHandler +qualname=hypercorn +propagate=0 + +[logger_alembic] +level=INFO +handlers=simpleHandler +qualname=alembic +propagate=0 + +[handler_simpleHandler] +class=StreamHandler +level=DEBUG +formatter=simpleFormatter +args=(sys.stdout,) + +[handler_detailedHandler] +class=StreamHandler +level=DEBUG +formatter=detailedFormatter +args=(sys.stdout,) + +[formatter_simpleFormatter] +format=%(asctime)s %(levelname)-5s | %(name)s: %(message)s +datefmt=%H:%M:%S + +[formatter_detailedFormatter] +format=%(asctime)s %(levelname)-5s | %(name)s.%(funcName)s() @ L%(lineno)d: %(message)s +datefmt=%H:%M:%S diff --git a/test/setup.sh b/test/setup.sh index 2eebe9cc..191a73d8 100644 --- a/test/setup.sh +++ b/test/setup.sh @@ -30,6 +30,7 @@ backend = sqlite name = aur.db [options] +aurwebdir = $TOPLEVEL aur_location = https://aur.archlinux.org aur_request_ml = aur-requests@lists.archlinux.org enable-maintenance = 0