aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2025-05-02 09:46:50 -0500
committerFrederick Muriuki Muriithi2025-05-02 09:46:50 -0500
commite3687f8a56ea0928d95a4554ec05046c378025b0 (patch)
tree9fa3cce02b87be9ecf0d6a5dc0e056dfb36765bb
parent82d63dd1ab4e8647568963ffc025e9a2b08f7f9d (diff)
downloadgn-uploader-e3687f8a56ea0928d95a4554ec05046c378025b0.tar.gz
PoC: Use independent module-level loggers with application
Using flask.current_app.logger for logging in modules leads to the modules requiring an app context, even when the module itself could be used outside of the application. This commit provides a proof-of-concept (really, me finally putting in the effort to figure out logging) for how we could allow independent loggers at the module level, that can then be hooked up to the main logging in the system in question.
-rw-r--r--uploader/__init__.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/uploader/__init__.py b/uploader/__init__.py
index 69d34f7..f5f6641 100644
--- a/uploader/__init__.py
+++ b/uploader/__init__.py
@@ -55,6 +55,11 @@ def setup_logging(app: Flask) -> Flask:
"SERVER_SOFTWARE", "").split('/')
return __log_gunicorn__(app) if bool(software) else __log_dev__(app)
+def setup_modules_logging(app_logger):
+ """Setup module-level loggers to the same log-level as the application."""
+ loglevel = logging.getLevelName(app_logger.getEffectiveLevel())
+ logging.getLogger("uploader.publications.models").setLevel(loglevel)
+
def create_app(config: dict = {}):
"""The application factory.
@@ -88,6 +93,7 @@ def create_app(config: dict = {}):
default_timeout=int(app.config["SESSION_FILESYSTEM_CACHE_TIMEOUT"]))
setup_logging(app)
+ setup_modules_logging(app.logger)
# setup jinja2 symbols
app.add_template_global(lambda : request.url, name="request_url")