aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMunyoki Kilyungi2022-08-23 22:02:26 +0300
committerBonfaceKilz2022-08-31 23:14:30 +0300
commit83fe39abf6e515baec46bdedb9e7b4d246bebdfc (patch)
tree2258715f4adcdb95334b40cc9d72a98d8414c83a
parentff4185334ddc5e6e32fdb1bf44ad6ea9065b0e01 (diff)
downloadgenenetwork2-83fe39abf6e515baec46bdedb9e7b4d246bebdfc.tar.gz
Replace debug with error logs in Except block pre/post a session
Put error logs in an Except block for easier parsing and re-word the error messages in them. * wqflask/wqflask/views.py: Delete "utility.logger" and "logger". (connect_db): Delete "g._database". Delete "logger.debug()". Use "app.logger.error" in Except block. (shutdown_session): Delete "logger.debug()". Use "app.logger.error" in Except block.
-rw-r--r--wqflask/wqflask/views.py24
1 files changed, 11 insertions, 13 deletions
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py
index e054cd49..d80d557b 100644
--- a/wqflask/wqflask/views.py
+++ b/wqflask/wqflask/views.py
@@ -100,32 +100,30 @@ from utility.benchmark import Bench
from pprint import pformat as pf
-import utility.logger
-
Redis = get_redis_conn()
-logger = utility.logger.getLogger(__name__)
-
@app.before_request
def connect_db():
db = getattr(g, '_database', None)
if request.endpoint not in ("static", "js") and db is None:
- logger.debug(
- f"Creating a database connection\n"
- f"\t\tfor request: {request.endpoint}")
- g.db = g._database = sqlalchemy.create_engine(
- SQL_URI, encoding="latin1")
+ try:
+ g.db = sqlalchemy.create_engine(
+ SQL_URI, encoding="latin1")
+ except Exception: # Capture everything
+ app.logger.error(f"DATABASE: Error creating connection for: {request.endpoint}")
@app.teardown_appcontext
def shutdown_session(exception=None):
db = getattr(g, '_database', None)
if db is not None:
- logger.debug(f"Removing the session")
- g.db.dispose()
- g.db = None
- logger.debug(f"g.db: {g.db}\n\tg._database: {g._database}")
+ try:
+ g.db.dispose()
+ except Exception: # Capture Everything
+ app.logger.error(f"DATABASE: Error disposing: {g.db=}")
+ finally: # Reset regardless of what happens
+ g.db = None
@app.errorhandler(Exception)