aboutsummaryrefslogtreecommitdiff
path: root/qc_app/__init__.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-03-19 15:54:24 +0300
committerFrederick Muriuki Muriithi2024-03-19 15:54:24 +0300
commit77fc426d35cf88af768dfac281e6a4979ed451fc (patch)
treea3f2d90564e14f9832042d8aac7067f22f62507d /qc_app/__init__.py
parentf22c423375487149f4f485d83c4a083f3ca0dbfd (diff)
downloadgn-uploader-77fc426d35cf88af768dfac281e6a4979ed451fc.tar.gz
Set up application logging.
Diffstat (limited to 'qc_app/__init__.py')
-rw-r--r--qc_app/__init__.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/qc_app/__init__.py b/qc_app/__init__.py
index 43831d8..c9756a1 100644
--- a/qc_app/__init__.py
+++ b/qc_app/__init__.py
@@ -1,7 +1,9 @@
"""The Quality-Control Web Application entry point"""
-
import os
+import sys
+import logging
from pathlib import Path
+from logging import StreamHandler
from flask import Flask
@@ -18,6 +20,15 @@ def override_settings_with_envvars(
for setting in (key for key in app.config if key not in ignore):
app.config[setting] = os.environ.get(setting) or app.config[setting]
+def setup_logging(app: Flask):
+ """Setup application logging"""
+ handler_stderr = StreamHandler(stream=sys.stderr)
+ app.logger.addHandler(handler_stderr)
+
+ rootlogger = logging.getLogger()
+ rootlogger.addHandler(handler_stderr)
+ rootlogger.setLevel(app.config["LOG_LEVEL"])
+
def create_app():
"""The application factory"""
app = Flask(__name__)
@@ -27,6 +38,7 @@ def create_app():
app.config.from_envvar("QCAPP_CONF") # Override defaults with instance path
override_settings_with_envvars(app, ignore=tuple())
+ setup_logging(app)
if "QCAPP_SECRETS" in os.environ:
app.config.from_envvar("QCAPP_SECRETS")