Ticket #3038 enhancement closed duplicate
Logfile rotation continues infinitely
| Reported by: | colin | Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | |
| Component: | core | Keywords: | |
| Cc: | Branch: | ||
| Author: | Launchpad Bug: |
Description
Proposed fix (2.5.0):
--- logfile.py 2008-02-18 09:48:00.000000000 +0200
+++ logfile.py 2008-02-18 09:54:43.000000000 +0200
@@ -90,10 +90,12 @@
"""A log file that can be rotated.
A rotateLength of None disables automatic log rotation.
+ A maxFiles of None disables the limit on the maximum number of files created
"""
- def __init__(self, name, directory, rotateLength=1000000, defaultMode=None):
+ def __init__(self, name, directory, rotateLength=1000000, defaultMode=None, maxFiles=10):
BaseLogFile.__init__(self, name, directory, defaultMode)
self.rotateLength = rotateLength
+ self.maxFiles = maxFiles
def _openFile(self):
BaseLogFile._openFile(self)
@@ -126,7 +128,8 @@
logs = self.listLogs()
logs.reverse()
for i in logs:
- os.rename("%s.%d" % (self.path, i), "%s.%d" % (self.path, i + 1))
+ if (not self.maxFiles) or (i < self.maxFiles):
+ os.rename("%s.%d" % (self.path, i), "%s.%d" % (self.path, i + 1))
self._file.close()
os.rename(self.path, "%s.1" % self.path)
self._openFile()
Change History
Note: See
TracTickets for help on using
tickets.
