From fa9a3929b8cf6f98d35ec99e45ca0ac97907d474 Mon Sep 17 00:00:00 2001 From: Dave Schuyler Date: Fri, 21 May 2004 02:03:41 +0000 Subject: [PATCH] added close and __del__ --- direct/src/directnotify/RotatingLog.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/direct/src/directnotify/RotatingLog.py b/direct/src/directnotify/RotatingLog.py index 48b23f2623..68f2c7bf09 100755 --- a/direct/src/directnotify/RotatingLog.py +++ b/direct/src/directnotify/RotatingLog.py @@ -10,10 +10,10 @@ class RotatingLog: to a new file if the prior file is too large or after a time interval. """ - def __init__(self, path="./log_file", timeInterval=24, megabyteLimit=1024): + def __init__(self, path="./log_file", hourInterval=24, megabyteLimit=1024): """ path is a full or partial path with file name. - timeInterval is the number of hours at which to rotate the file. + hourInterval is the number of hours at which to rotate the file. megabyteLimit is the number of megabytes of file size the log may grow to, afterwhich the log is rotated. """ @@ -21,12 +21,22 @@ class RotatingLog: self.timeInterval=None self.timeLimit=None self.sizeLimit=None - if timeInterval is not None: - self.timeInterval=timeInterval*60*60 + if hourInterval is not None: + self.timeInterval=hourInterval*60*60 self.timeLimit=time.time()+self.timeInterval if megabyteLimit is not None: self.sizeLimit=megabyteLimit*1024*1024 + def __del__(self): + self.close() + + def close(self): + print "close" + if hasattr(self, "file"): + self.file.flush() + self.file.close() + del self.file + def shouldRotate(self): """ Returns a bool about whether a new log file should @@ -59,10 +69,7 @@ class RotatingLog: path=self.filePath() file=open(path, "a") if file: - if hasattr(self, "file"): - self.file.flush() - self.file.close() - del self.file + self.close() self.file=file if self.timeLimit is not None and time.time() > self.timeLimit: self.timeLimit=time.time()+self.timeInterval