Skip to content

Commit 18a4a3d

Browse files
committed
Added a flushHandlers() function to the logger.
1 parent 4e0c2f3 commit 18a4a3d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

adafruit_logging.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ def emit(self, record: LogRecord) -> None:
179179

180180
raise NotImplementedError()
181181

182+
def flush(self) -> None:
183+
"""Placeholder for flush function in subclasses."""
184+
182185

183186
# pylint: disable=too-few-public-methods
184187
class StreamHandler(Handler):
@@ -415,6 +418,13 @@ def getEffectiveLevel(self) -> int:
415418

416419
return self._level
417420

421+
def flushHandlers(self) -> None:
422+
"""Flush all handlers. This will ensure that all data is immediately written to the streams.
423+
This can be useful if you need to make sure the log is written before a reset.
424+
"""
425+
for handlerName in self._handlers:
426+
handlerName.flush()
427+
418428
def addHandler(self, hdlr: Handler) -> None:
419429
"""Adds the handler to this logger.
420430

0 commit comments

Comments
 (0)