aboutsummaryrefslogtreecommitdiff
path: root/gn_libs/debug.py
diff options
context:
space:
mode:
Diffstat (limited to 'gn_libs/debug.py')
-rw-r--r--gn_libs/debug.py29
1 files changed, 24 insertions, 5 deletions
diff --git a/gn_libs/debug.py b/gn_libs/debug.py
index 6b7173b..7ad10e0 100644
--- a/gn_libs/debug.py
+++ b/gn_libs/debug.py
@@ -1,6 +1,7 @@
"""Debug utilities"""
import logging
-from flask import current_app
+import importlib.util
+from typing import Callable
__this_module_name__ = __name__
@@ -8,10 +9,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"""
@@ -20,3 +27,15 @@ def __pk__(*args):
logger = getLogger(__this_module_name__)
logger.debug("%s: %s", title_vals, value)
return value
+
+
+def make_peeker(logger: logging.Logger) -> Callable:
+ """Make a peeker function that's very much like __pk__ but that uses the
+ given logger."""
+ def peeker(*args):
+ value = args[-1]
+ title_vals = " => ".join(args[0:-1])
+ logger.debug("%s: %s", title_vals, value)
+ return value
+
+ return peeker