class CaptureLogHandler(logging.StreamHandler): """A logging handler that stores log records and the log text.""" def __init__(self): """Creates a new log handler.""" logging.StreamHandler.__init__(self) self.records = [] self.stream = TextIO() def close(self): """Close this log handler and its underlying stream.""" self.stream.close() logging.StreamHandler.close(self) def emit(self, record): """Keep the log records in a list in addition to the log text.""" self.records.append(record) logging.StreamHandler.emit(self, record)
def __init__(self): """Creates a new log handler.""" logging.StreamHandler.__init__(self) self.records = [] self.stream = TextIO()