[Twisted-Python] twisted.lumberjack clobbers existing logs
![](https://secure.gravatar.com/avatar/b3407ff6ccd34c6e7c7a9fdcfba67a45.jpg?s=120&d=mm&r=g)
Hi everyone... I like the twisted.lumberjack module that was recently added, but I think it has a small buglet. It checks the size of the existing log file, but then opens it in mode "w", truncating it. Thus, I suggest the last line of LogFile._openFile should change from: self._file = open(self.path, "w") to: self._file = open(self.path, "a") -Andrew.
![](https://secure.gravatar.com/avatar/433365de0f787faa3ed3e6dd1da5884f.jpg?s=120&d=mm&r=g)
Andrew Bennetts wrote:
Actually, "a" mode is a bad idea, since according to the docs has inconsistent behaviour: "on *some* Unix systems means that *all* writes append to the end of the file, regardless of the current seek position)." But you're write about that. I'll fix it ASAP. Thanks for the bug report!
![](https://secure.gravatar.com/avatar/433365de0f787faa3ed3e6dd1da5884f.jpg?s=120&d=mm&r=g)
Andrew Bennetts wrote:
I considered that, but when would a log file ever want to do otherwise?
"a" also screws up seek()s, which I'll need for the remote log viewing service. In general, "a" seems like a bad idea since its behavior is inconsistent.
I'd be interested to know what a portable way to append to a file is, though.
# assuming "file" exists f = open("file", "r+") f.seek(0, 2) see the code I checked in for a complete example.
![](https://secure.gravatar.com/avatar/433365de0f787faa3ed3e6dd1da5884f.jpg?s=120&d=mm&r=g)
Andreas Kostyrka wrote:
Well, this assumes that there is only one writer for the file.
The code in twisted.python.log assures that there is only one writer at any given time. We want to do this on the Python side, not using OS features, in order to make the code as portables as possible.
![](https://secure.gravatar.com/avatar/812cc4936ca92a5ad9073f521a32b7fb.jpg?s=120&d=mm&r=g)
Yepp, http://www.twistedmatrix.com/foo/ does the exception-dance, but not http://www.twistedmatrix.com/foo obviously. So, this isn't anything terrible and hard, but I just couldn't recreate the situation here (win2k). Probably fixed, but somebody ought to know. mvh. Benjamin Bruheim Teknisk Leder, In/Out Bergen :: www.inout.no
![](https://secure.gravatar.com/avatar/433365de0f787faa3ed3e6dd1da5884f.jpg?s=120&d=mm&r=g)
Andrew Bennetts wrote:
Actually, "a" mode is a bad idea, since according to the docs has inconsistent behaviour: "on *some* Unix systems means that *all* writes append to the end of the file, regardless of the current seek position)." But you're write about that. I'll fix it ASAP. Thanks for the bug report!
![](https://secure.gravatar.com/avatar/433365de0f787faa3ed3e6dd1da5884f.jpg?s=120&d=mm&r=g)
Andrew Bennetts wrote:
I considered that, but when would a log file ever want to do otherwise?
"a" also screws up seek()s, which I'll need for the remote log viewing service. In general, "a" seems like a bad idea since its behavior is inconsistent.
I'd be interested to know what a portable way to append to a file is, though.
# assuming "file" exists f = open("file", "r+") f.seek(0, 2) see the code I checked in for a complete example.
![](https://secure.gravatar.com/avatar/433365de0f787faa3ed3e6dd1da5884f.jpg?s=120&d=mm&r=g)
Andreas Kostyrka wrote:
Well, this assumes that there is only one writer for the file.
The code in twisted.python.log assures that there is only one writer at any given time. We want to do this on the Python side, not using OS features, in order to make the code as portables as possible.
![](https://secure.gravatar.com/avatar/812cc4936ca92a5ad9073f521a32b7fb.jpg?s=120&d=mm&r=g)
Yepp, http://www.twistedmatrix.com/foo/ does the exception-dance, but not http://www.twistedmatrix.com/foo obviously. So, this isn't anything terrible and hard, but I just couldn't recreate the situation here (win2k). Probably fixed, but somebody ought to know. mvh. Benjamin Bruheim Teknisk Leder, In/Out Bergen :: www.inout.no
participants (5)
-
Andreas Kostyrka
-
Andrew Bennetts
-
Andrew Bennetts
-
Benjamin Bruheim
-
Itamar Shtull-Trauring