| 26 | |
| 27 | # Keeper Commander uses logging module to communicate with the user. |
| 28 | class ScriptLogHandler(logging.Handler): |
| 29 | def __init__(self): |
| 30 | super(ScriptLogHandler, self).__init__() |
| 31 | self.errors = [] |
| 32 | |
| 33 | def emit(self, record: LogRecord) -> None: |
| 34 | message = record.msg % record.args |
| 35 | self.errors.append(message) |
| 36 | |
| 37 | def clear_errors(self): |
| 38 | self.errors.clear() |
| 39 | |
| 40 | def has_error(self): |
| 41 | return len(self.errors) > 0 |
| 42 | |
| 43 | # Configure logging |
| 44 | slh = ScriptLogHandler() |