From 58101923291172e9999ffc607d5f3d1b9507ccfb Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 14 Apr 2022 08:56:31 +0300 Subject: Debug: Add logging to track db connection creation and stopping As part of debugging the "Too many connections" error to the database, this commit adds logging to track the creation of connections to the database, and their eventual closing. --- wqflask/wqflask/views.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'wqflask') diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index 2138146c..fdb49c7f 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -110,6 +110,9 @@ logger = utility.logger.getLogger(__name__) 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") @@ -118,8 +121,10 @@ def connect_db(): 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}") @app.errorhandler(Exception) -- cgit v1.2.3