[Twisted-Python] Addition to twisted.python.logfile

John Abel john.abel at pa.press.net
Thu Oct 17 10:03:28 EDT 2002


Hi,

Please go gently with me, this is my first submitted "enhancement"! 
 I've made a small change to twisted.python.logfile, adding the option 
to gzip the log files, once they've been renamed (default is not to 
compress).

I couldn't find any info on submitting a change, so I've attached the 
output from a diff logfile.py logfileII.py

Hope you find it useful.

Regards

John

< import os, stat, glob, string
---
 > import os, stat, glob, string, gzip, fileinput, re
37d36
<
39c38
<     def __init__(self, name, directory, rotateLength=1000000):
---
 >     def __init__(self, name, directory, rotateLength=1000000, 
compressLog=0):
43a43,49
 >         if not compressLog in [0,1]:
 >             self.compressLog = 0
 >         else:
 >             self.compressLog = compressLog
 >         self.globFilePattern = ["%s.*", "%s.*.gz"]
 >         self.renameFilePattern = ["%s.%d","%s.%d.gz"]
 >         self.rePattern = [".*\.(\d)$",".*\.(\d)\.gz$"]
90c96
<         for name in glob.glob("%s.*" % self.path):
---
 >         for name in glob.glob(self.globFilePattern[self.compressLog] 
% self.path):
92,94c98,102
<                 counter = int(string.split(name, '.')[-1])
<                 if counter:
<                     result.append(counter)
---
 >                 reCounter = 
re.match(self.rePattern[self.compressLog],name)
 >                 if reCounter:
 >                     counter = int( reCounter.group(1) )
 >                     if counter:
 >                         result.append(counter)
111c119
<             os.rename("%s.%d" % (self.path, i), "%s.%d" % (self.path, 
i + 1))
---
 >             os.rename(self.renameFilePattern[self.compressLog] % 
(self.path, i), self.renameFilePattern[self.compressLog] % (self.path, i 
+ 1113a122,126







More information about the Twisted-Python mailing list