diff options
author | Frederick Muriuki Muriithi | 2025-01-21 15:58:29 -0600 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2025-01-21 16:09:09 -0600 |
commit | 761ee64e832dcd38dc1b6d0701b48ee468fb7113 (patch) | |
tree | 3406d498e47823dba70abefdd0a53594decd00e9 /gn_libs | |
parent | 4dfe8e5820ceffb9941ff38c704fefbe7440047e (diff) | |
download | gn-libs-761ee64e832dcd38dc1b6d0701b48ee468fb7113.tar.gz |
Only use flask modules if flask is present and 'current_app' is set.
Diffstat (limited to 'gn_libs')
-rw-r--r-- | gn_libs/debug.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/gn_libs/debug.py b/gn_libs/debug.py index 6b7173b..c1b896e 100644 --- a/gn_libs/debug.py +++ b/gn_libs/debug.py @@ -1,6 +1,6 @@ """Debug utilities""" import logging -from flask import current_app +import importlib.util __this_module_name__ = __name__ @@ -8,10 +8,16 @@ __this_module_name__ = __name__ # pylint: disable=invalid-name def getLogger(name: str): """Return a logger""" - return ( - logging.getLogger(name) - if not bool(current_app) - else current_app.logger) + flask_spec = importlib.util.find_spec("flask") + if bool(flask_spec): + current_app = importlib.import_module("flask").current_app + return ( + logging.getLogger(name) + if not bool(current_app) + else current_app.logger) + + return logging.getLogger(name) + def __pk__(*args): """Format log entry""" |