about summary refs log tree commit diff
path: root/gn_libs/debug.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2025-06-04 10:27:35 -0500
committerFrederick Muriuki Muriithi2025-06-04 10:27:35 -0500
commit44a251732b980b699e2ea00fb9405db39bb6e08f (patch)
treee2ff8bf58897d29dd5668694515956c736f272ef /gn_libs/debug.py
parent7cfd6cbdbc6a00a90d6c5854889aaecbdfcb9dfe (diff)
downloadgn-libs-44a251732b980b699e2ea00fb9405db39bb6e08f.tar.gz
Add function to make a "peeker" function.
The current peeker function `__pk__` has pre-specified logger(s) which
are not always present in all environments, and even when present,
might not have the appropriate configuration. This commit provides a
way to build a peeker function that is passed the logger to use.
Diffstat (limited to 'gn_libs/debug.py')
-rw-r--r--gn_libs/debug.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/gn_libs/debug.py b/gn_libs/debug.py
index c1b896e..7ad10e0 100644
--- a/gn_libs/debug.py
+++ b/gn_libs/debug.py
@@ -1,6 +1,7 @@
 """Debug utilities"""
 import logging
 import importlib.util
+from typing import Callable
 
 __this_module_name__ = __name__
 
@@ -26,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