Skip to content

logging.FileHandler not adding new lines to log file #628

Open
@AT0myks

Description

@AT0myks

Just tried the updated logging module to replace the StreamHandler and FileHandler adapted from CPython that I was previously using. Thank you @iabdalkader for this update.

StreamHandler works as expected, however I noticed that I wasn't getting any new lines in my log file.
I looked at the previous code and saw that there's a flush after the write in StreamHandler.emit.
Using this subclass for FileHandler, it works like before:

class MyStreamHandler(StreamHandler):

    def flush(self):
        if self.stream and hasattr(self.stream, "flush"):
            self.stream.flush()

    def emit(self, record):
        super().emit(record)
        self.flush()

Is there a reason for not doing a flush in emit, maybe something specific to MicroPython that I'm not aware of?

  • MicroPython and board: MicroPython v1.19.1-915-g2bcd88d55 on 2023-03-02; Raspberry Pi Pico W with RP2040
  • logging version: 0.5 installed with mip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions