Total Complexity | 4 |
Total Lines | 33 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | """Implements the "magic" to create `logging` records for the caller.""" |
||
2 | |||
3 | import sys |
||
4 | import logging |
||
5 | import inspect |
||
6 | |||
7 | from . import helpers |
||
8 | |||
9 | |||
10 | def create_logger_record(level, message, *args, exc_info=None, **kwargs): |
||
11 | if not helpers.initialized and 'pytest' not in sys.modules: |
||
12 | helpers.init() |
||
13 | |||
14 | frame, filename, lineno, *_ = inspect.stack()[3] |
||
15 | module = inspect.getmodule(frame) |
||
16 | |||
17 | logger = logging.getLogger() |
||
18 | if not logger.isEnabledFor(level): |
||
19 | return |
||
20 | |||
21 | record = logger.makeRecord( |
||
22 | module.__name__, |
||
23 | level, |
||
24 | fn=filename, |
||
25 | lno=lineno, |
||
26 | msg=message, |
||
27 | args=args, |
||
28 | exc_info=exc_info, |
||
29 | extra=kwargs, |
||
30 | sinfo=None, |
||
31 | ) |
||
32 | logger.handle(record) |
||
33 |