diff options
Diffstat (limited to 'gn_auth/__init__.py')
| -rw-r--r-- | gn_auth/__init__.py | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/gn_auth/__init__.py b/gn_auth/__init__.py index 658f034..d6591e5 100644 --- a/gn_auth/__init__.py +++ b/gn_auth/__init__.py @@ -2,6 +2,7 @@ import os import sys import logging +import warnings from pathlib import Path from typing import Optional, Callable @@ -18,9 +19,16 @@ from gn_auth.auth.authentication.oauth2.server import setup_oauth2_server from . import settings from .errors import register_error_handlers +## Configure warnings: ## +# https://docs.python.org/3/library/warnings.html#the-warnings-filter +# filters form: (action, message, category, module, lineno) +warnings.filterwarnings(action="always", category=DeprecationWarning) + + class ConfigurationError(Exception): """Raised in case of a configuration error.""" + def check_mandatory_settings(app: Flask) -> None: """Verify that mandatory settings are defined in the application""" undefined = tuple( @@ -70,7 +78,16 @@ def gunicorn_loggers(appl: Flask) -> None: appl.logger.setLevel(logger.level) -def setup_logging(appl: Flask) -> Callable[[Flask], None]: +_LOGGABLE_MODULES_ = ( + "gn_auth.errors", + "gn_auth.errors.common", + "gn_auth.errors.authlib", + "gn_auth.errors.http.http_4xx_errors", + "gn_auth.errors.http.http_5xx_errors" +) + + +def setup_logging(appl: Flask) -> None: """ Setup the loggers according to the WSGI server used to run the application. """ @@ -80,8 +97,13 @@ def setup_logging(appl: Flask) -> Callable[[Flask], None]: software, *_version_and_comments = os.environ.get( "SERVER_SOFTWARE", "").split('/') if bool(software): - return gunicorn_loggers(appl) - return dev_loggers(appl) + gunicorn_loggers(appl) + else: + dev_loggers(appl) + + loglevel = logging.getLevelName(appl.logger.getEffectiveLevel()) + for module_logger in _LOGGABLE_MODULES_: + logging.getLogger(module_logger).setLevel(loglevel) def create_app(config: Optional[dict] = None) -> Flask: |
