Skip to content

Commit c9c6450

Browse files
authored
Merge pull request #58 from ilikecake/file_flush_fix
Add flush to the file write functions
2 parents f683fef + 3cc0d4f commit c9c6450

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

adafruit_logging.py

+11
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):
@@ -206,6 +209,12 @@ def emit(self, record: LogRecord) -> None:
206209
"""
207210
self.stream.write(self.format(record) + self.terminator)
208211

212+
def flush(self) -> None:
213+
"""flush the stream. You might need to call this if your messages
214+
are not appearing in the log file.
215+
"""
216+
self.stream.flush()
217+
209218

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

243253

244254
class RotatingFileHandler(FileHandler):
@@ -338,6 +348,7 @@ def emit(self, record: LogRecord) -> None:
338348
):
339349
self.doRollover()
340350
self.stream.write(self.format(record))
351+
self.stream.flush()
341352

342353

343354
class NullHandler(Handler):

0 commit comments

Comments
 (0)