I am trying to implement my own version of DailyLogFile
from twisted.python.logfile import DailyLogFile class NDailyLogFile(DailyLogFile): def __init__(self, name, directory, rotateAfterN = 1, defaultMode=None): DailyLogFile.__init__(self, name, directory, defaultMode) # why do not use super. here? lisibility maybe? # self.rotateAfterN = rotateAfterN def shouldRotate(self): """Rotate when N days have passed since file creation""" delta = datetime.date(*self.toDate()) - datetime.date(*self.toDate(self.createdOn)) return delta > datetime.timedelta(self.rotateAfterN) def __getstate__(self): state = BaseLogFile.__getstate__(self) del state["rotateAfterN"] return state threadable.synchronize(NDailyLogFile)
but it looks like I missed the fundamental process of subclassing Python ... as I get this error:
Traceback (most recent call last): File "/home/twistedtestproxy04.py", line 88, in <module> import ndailylogfile File "/home/ndailylogfile.py", line 56, in <module> threadable.synchronize(NDailyLogFile) File "/home/lt/mpv0/lib/python2.6/site-packages/twisted/python/threadable.py", line 71, in synchronize sync = _sync(klass, klass.__dict__[methodName]) KeyError: 'write'
so I need to explicitly add and define other methods such as Write and rotate , for example:
class NDailyLogFile(DailyLogFile): [...] def write(self, data):
while I thought that it would inherit from the base class correctly. Please note that I’m not doing anything, just calling it “super”,
please, can someone explain why I am mistaken in my first idea that there is no need to add the Write method?
Is there a way to tell Python inside my NDailyLogFile that it has all DailyLogFile methods that are not defined directly from its mother class? So that it prevents this error king _sync(klass, klass.__dict__[methodName] and avoids specifying explicitly?
(DailyLogFile source code that inspired me to extract from a curved source https://github.com/tzuryby/freespeech/blob/master/twisted/python/logfile.py )
EDIT: about using super , I get:
File "/home/lt/inwork/ndailylogfile.py", line 57, in write super.write(self, data) exceptions.AttributeError: type object 'super' has no attribute 'write'
therefore will not use it. Mine, although it was right ... I must have missed something.