diff --git a/adafruit_logging.py b/adafruit_logging.py index 370f252..f1e171f 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): @@ -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 @@ -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): @@ -338,6 +348,7 @@ def emit(self, record: LogRecord) -> None: ): self.doRollover() self.stream.write(self.format(record)) + self.stream.flush() class NullHandler(Handler):