Переглянути джерело

removed print; changed some comments; added seek; changed error text

Dave Schuyler 21 роки тому
батько
коміт
e1f734f589
1 змінених файлів з 9 додано та 4 видалено
  1. 9 4
      direct/src/directnotify/RotatingLog.py

+ 9 - 4
direct/src/directnotify/RotatingLog.py

@@ -15,7 +15,9 @@ class RotatingLog:
         path is a full or partial path with file name.
         path is a full or partial path with file name.
         hourInterval 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
         megabyteLimit is the number of megabytes of file size the log
-            may grow to, afterwhich the log is rotated.
+            may grow to, after which the log is rotated.  Note: The log
+            file may get a bit larger than limit do to writing out whole
+            lines (last line may exceed megabyteLimit or "megabyteGuidline").
         """
         """
         self.path=path
         self.path=path
         self.timeInterval=None
         self.timeInterval=None
@@ -31,7 +33,6 @@ class RotatingLog:
         self.close()
         self.close()
 
 
     def close(self):
     def close(self):
-        print "close"
         if hasattr(self, "file"):
         if hasattr(self, "file"):
             self.file.flush()
             self.file.flush()
             self.file.close()
             self.file.close()
@@ -70,12 +71,16 @@ class RotatingLog:
         file=open(path, "a")
         file=open(path, "a")
         if file:
         if file:
             self.close()
             self.close()
+            # This should be redundant with "a" open() mode, 
+            # but on some platforms tell() will return 0 
+            # until the first write:
+            file.seek(0, 2)
             self.file=file
             self.file=file
             if self.timeLimit is not None and time.time() > self.timeLimit:
             if self.timeLimit is not None and time.time() > self.timeLimit:
                 self.timeLimit=time.time()+self.timeInterval
                 self.timeLimit=time.time()+self.timeInterval
         else:
         else:
-            # I guess we keep writing to the old file.
-            print "unable to open new log file \"%s\""%(path,)
+            # We'll keep writing to the old file, if available.
+            print "RotatingLog error: Unable to open new log file \"%s\"."%(path,)
     
     
     def write(self, data):
     def write(self, data):
         """
         """