MCPcopy
hub / github.com/Delgan/loguru / ErrorInterceptor

Class ErrorInterceptor

loguru/_error_interceptor.py:5–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3
4
5class ErrorInterceptor:
6 def __init__(self, should_catch, handler_id):
7 self._should_catch = should_catch
8 self._handler_id = handler_id
9
10 def should_catch(self):
11 return self._should_catch
12
13 def print(self, record=None, *, exception=None):
14 if not sys.stderr:
15 return
16
17 if exception is None:
18 type_, value, traceback_ = sys.exc_info()
19 else:
20 type_, value, traceback_ = (type(exception), exception, exception.__traceback__)
21
22 try:
23 sys.stderr.write("--- Logging error in Loguru Handler #%d ---\n" % self._handler_id)
24 try:
25 record_repr = str(record)
26 except Exception:
27 record_repr = "/!\\ Unprintable record /!\\"
28 sys.stderr.write("Record was: %s\n" % record_repr)
29 traceback.print_exception(type_, value, traceback_, None, sys.stderr)
30 sys.stderr.write("--- End of logging error ---\n")
31 except OSError:
32 pass
33 finally:
34 del type_, value, traceback_

Callers 1

addMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…