Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flush to the file write functions #58

Merged
merged 4 commits into from
Jun 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading