Counts the number of WARNING or higher log records.
| 81 | |
| 82 | |
| 83 | class LogCounter(logging.Filter): |
| 84 | """Counts the number of WARNING or higher log records.""" |
| 85 | |
| 86 | def __init__(self, *args, **kwargs): |
| 87 | super().__init__(*args, **kwargs) |
| 88 | self.info_count = self.warning_count = self.error_count = 0 |
| 89 | |
| 90 | def filter(self, record): |
| 91 | if record.levelno >= logging.ERROR: |
| 92 | self.error_count += 1 |
| 93 | elif record.levelno >= logging.WARNING: |
| 94 | self.warning_count += 1 |
| 95 | elif record.levelno >= logging.INFO: |
| 96 | self.info_count += 1 |
| 97 | return True |
| 98 | |
| 99 | |
| 100 | class CountingStderr(io.IOBase): |