Skip to content

Commit

Permalink
Merge pull request #58 from ilikecake/file_flush_fix
Browse files Browse the repository at this point in the history
Add flush to the file write functions
  • Loading branch information
FoamyGuy committed Jun 16, 2024
2 parents f683fef + 3cc0d4f commit c9c6450
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 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 @@ -206,6 +209,12 @@ def emit(self, record: LogRecord) -> None:
"""
self.stream.write(self.format(record) + self.terminator)

def flush(self) -> None:
"""flush the stream. You might need to call this if your messages
are not appearing in the log file.
"""
self.stream.flush()


class FileHandler(StreamHandler):
"""File handler for working with log files off of the microcontroller (like
Expand Down Expand Up @@ -239,6 +248,7 @@ def emit(self, record: LogRecord) -> None:
:param record: The record (message object) to be logged
"""
self.stream.write(self.format(record))
self.stream.flush()


class RotatingFileHandler(FileHandler):
Expand Down Expand Up @@ -338,6 +348,7 @@ def emit(self, record: LogRecord) -> None:
):
self.doRollover()
self.stream.write(self.format(record))
self.stream.flush()


class NullHandler(Handler):
Expand Down

0 comments on commit c9c6450

Please sign in to comment.