diff --git a/adafruit_logging.py b/adafruit_logging.py index 03a0351..006f431 100644 --- a/adafruit_logging.py +++ b/adafruit_logging.py @@ -179,6 +179,9 @@ def emit(self, record: LogRecord) -> None: raise NotImplementedError() + def flush(self) -> None: + """Placeholder for flush function in subclasses.""" + # pylint: disable=too-few-public-methods class StreamHandler(Handler): @@ -415,6 +418,13 @@ def getEffectiveLevel(self) -> int: return self._level + def flushHandlers(self) -> None: + """Flush all handlers. This will ensure that all data is immediately written to the streams. + This can be useful if you need to make sure the log is written before a reset. + """ + for handlerName in self._handlers: + handlerName.flush() + def addHandler(self, hdlr: Handler) -> None: """Adds the handler to this logger.