Thanks to visit codestin.com
Credit goes to github.com

Skip to content

RotatingFileHandler formats the record twice #116267

Open
@serhiy-storchaka

Description

@serhiy-storchaka

RotatingFileHandler calls self.format() twice for every record -- first time to determine if rollover should occur, second time to write it to the stream. It is not optimal. Even if the IO time dominates in common cases, the formatting time may be non-trivial -- this is why formatting is delayed.

It is not easy to fix without duplicating the code and introducing a coupling between several handler classes. The simplest way -- check the current file size in shouldRollover(), without adding the size of the new record. This will make the size of backups slightly larger than maxBytes, but this calculation is already inaccurate (see #64336, #69128). This will automatically solve #116263.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance or resource usage

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions