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

TimedRotatingFileHandler and RotatingFileHandler open new streams in the wrong mode #298

Open
nhoad opened this issue Oct 1, 2019 · 1 comment

Comments

@nhoad
Copy link

nhoad commented Oct 1, 2019

TimedRotatingFileHandler and RotatingFileHandler's perform_rollover methods open the new stream in w mode, not a mode. The result is that if multiple processes are writing to logs, then they start competing with each other. Here's some test code that demonstrates:

import logbook
import datetime

log = logbook.Logger("test")
handler = logbook.TimedRotatingFileHandler("testlog.log", date_format='%Y-%m')

with handler:
    log.info("Testing")
    print(handler.stream)
    handler.perform_rollover(handler._get_timestamp(datetime.datetime.utcnow()))
    print(handler.stream)
    log.info("Testing 2")

With the output showing that the mode has changed:

<_io.TextIOWrapper name='/home/nhoad/testlog-2019-10.log' mode='a' encoding='utf-8'>
<_io.TextIOWrapper name='/home/nhoad/testlog-2019-10.log' mode='w' encoding='utf-8'>

Is there a reason that both of these methods not do self._open(self._mode) instead?

@nhoad
Copy link
Author

nhoad commented Jan 14, 2020

Can I get an update on this? This is causing a lot of issues for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant