| 3 | |
| 4 | |
| 5 | class 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_ |
no outgoing calls
no test coverage detected
searching dependent graphs…