Skip to content

Commit

Permalink
Added a flushHandlers() function to the logger.
Browse files Browse the repository at this point in the history
  • Loading branch information
ilikecake committed Jun 4, 2024
1 parent 4e0c2f3 commit 18a4a3d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions adafruit_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 18a4a3d

Please sign in to comment.