blob: 7ad10e0a8b5b086ae9daf2f91cba1868558d9a03 (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
"""Debug utilities"""
import logging
import importlib.util
from typing import Callable
__this_module_name__ = __name__
# pylint: disable=invalid-name
def getLogger(name: str):
"""Return a 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"""
value = args[-1]
title_vals = " => ".join(args[0:-1])
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
|