(self, record: logging.LogRecord)
| 95 | |
| 96 | class StackInfoFilter(logging.Filter): |
| 97 | def filter(self, record: logging.LogRecord) -> bool: |
| 98 | if record.levelno >= logging.ERROR: |
| 99 | # Only add stack trace info if there's an actual exception |
| 100 | exc_info = sys.exc_info() |
| 101 | if exc_info and exc_info[0] is not None: |
| 102 | # Capture the current stack trace as a string |
| 103 | stack = traceback.format_stack() |
| 104 | # Remove the last entries which are related to the logging machinery |
| 105 | stack = stack[:-3] # Adjust this number if needed |
| 106 | # Join the stack frames into a single string |
| 107 | stack_str = ''.join(stack) |
| 108 | setattr(record, 'stack_info', stack_str) |
| 109 | setattr(record, 'exc_info', exc_info) |
| 110 | return True |
| 111 | |
| 112 | |
| 113 | class NoColorFormatter(logging.Formatter): |
no outgoing calls