This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: TimedRotatingFileHandler's doRollover opens file in "w" mode
Type: Stage:
Components: Library (Lib) Versions: Python 2.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: vinay.sajip Nosy List: fastflo, nnorwitz, vinay.sajip
Priority: normal Keywords:

Created on 2007-04-27 07:30 by fastflo, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg31905 - (view) Author: Florian Schmidt (fastflo) Date: 2007-04-27 07:30
if TimedRotatingFileHandler does an doRollover() it opens the new file hardcoded with mode "w" whilst the baseclass FileHandler opens it with mode "a" if nothing else is specified in the constructor. it should use the same default behavior as FileHandler and/or give a way to specify another open-mode.

if multiple processes write to the same file, and one does the RollOver all other newly spawned processes write to the end of the new file but the still running first process who did the rollover will write from the beginning of the file - overwriting log entries from the other procs...
msg31906 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2007-04-28 01:40
This sounds like a logging module issue.
msg31907 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2007-04-28 12:50
Since there is no interprocess synchronisation in Python, writing to the same logging file from multiple processes is not supported. If you want output from multiple processes to end up in the same file, have all your processes send logging events to a SocketHandler, and set up a separate socket receiver (which could be in one of the processes) to receive the events and log to file. A working example is given here:

http://docs.python.org/lib/network-logging.html

Note that even if the system was changed to use 'a' rather than 'w', this would not eliminate potential problems with e.g. data in unflushed buffers, etc.
msg31908 - (view) Author: Florian Schmidt (fastflo) Date: 2007-04-29 15:29
i think opening the log file with "w" is inconsistent and therefore should be fixed.

as a comment: i do not need IPC/synchronisation if all processes are writing in append-mode to the same file. i am aware that sometimes log messages could get mixed up, but no single one will get completely lost (just eventually scattert if its a really big one).

for now we overloaded that function in our project. thanks!
History
Date User Action Args
2022-04-11 14:56:24adminsetgithub: 44906
2007-04-27 07:30:42fastflocreate