aboutsummaryrefslogtreecommitdiff
path: root/gn3/debug.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-09-12 08:48:38 -0500
committerFrederick Muriuki Muriithi2024-09-12 08:54:01 -0500
commita23eb674191572867d1161b2b43285e060781062 (patch)
treed2812e1ea4360014617fab9f926796e058a148f8 /gn3/debug.py
parentb75a3a463964fde6d68f0389f474fcf0aff4fe3b (diff)
downloadgenenetwork3-a23eb674191572867d1161b2b43285e060781062.tar.gz
Gracefully print out debug messages even outside app context
The flask.current_app object depends on the application context existing. In the case that no such context existing, then we still log out information, gracefully with this commit.
Diffstat (limited to 'gn3/debug.py')
-rw-r--r--gn3/debug.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/gn3/debug.py b/gn3/debug.py
index acc2402..3c88bd3 100644
--- a/gn3/debug.py
+++ b/gn3/debug.py
@@ -2,11 +2,17 @@
import logging
from flask import current_app
-logger = logging.getLogger(__name__)
+__this_module_name__ == __name__
+
+def getLogger():
+ return (
+ logging.getLogger(__name__)
+ if not bool(current_app)
+ else current_app.logger)
def __pk__(*args):
value = args[-1]
title_vals = " => ".join(args[0:-1])
- current_app.logger.setLevel(logging.DEBUG) # Force debug level since we assume we are using it!
- current_app.logger.debug("%s: %s", title_vals, value)
+ logger = getLogger()
+ logger.debug("%s: %s", title_vals, value)
return value