MCPcopy Index your code
hub / github.com/idank/explainshell / InterceptHandler

Class InterceptHandler

explainshell/logger/logging_interceptor.py:9–32  ·  view source on GitHub ↗

intercept log messages logged with the logging module source: https://loguru.readthedocs.io/en/stable/overview.html#entirely-compatible-with-standard-logging also see: https://stackoverflow.com/a/70620198

Source from the content-addressed store, hash-verified

7
8
9class InterceptHandler(logging.Handler):
10 """
11 intercept log messages logged with the logging module
12
13 source: https://loguru.readthedocs.io/en/stable/overview.html#entirely-compatible-with-standard-logging
14 also see: https://stackoverflow.com/a/70620198
15 """
16
17 def emit(self, record):
18 # Get corresponding Loguru level if it exists.
19 try:
20 level = logger.level(record.levelname).name
21 except ValueError:
22 level = record.levelno
23
24 # Find caller from where originated the logged message.
25 frame, depth = sys._getframe(6), 6
26 while frame and frame.f_code.co_filename == logging.__file__:
27 frame = frame.f_back
28 depth += 1
29
30 logger.opt(depth=depth, exception=record.exc_info).log(
31 level, record.getMessage()
32 )

Callers 1

runserver.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected