changeset 1855:472566340cd8

logfile: more flexible logging
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 08 Mar 2007 14:18:48 +0100
parents 2d54d55bc351
children 72ef28ba79b1
files MoinMoin/logfile/__init__.py
diffstat 1 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/logfile/__init__.py	Thu Mar 08 14:13:13 2007 +0100
+++ b/MoinMoin/logfile/__init__.py	Thu Mar 08 14:18:48 2007 +0100
@@ -7,6 +7,7 @@
     @copyright: 2005-2007 by Thomas Waldmann (MoinMoin:ThomasWaldmann)
     @license: GNU GPL, see COPYING for details.
 """
+import logging
 
 import os, codecs, errno
 from MoinMoin import config, wikiutil
@@ -34,8 +35,10 @@
         @param forward : read from offset on or from offset-size to offset
         @type forward: boolean
         """
+        self.loglevel = logging.NOTSET
         if forward:
             begin = offset
+            logging.log(self.loglevel, "LineBuffer.init: forward seek %d read %d" % (begin, size))
             file.seek(begin)
             lines = file.readlines(size)
         else:
@@ -44,6 +47,7 @@
                 size = offset
             else:
                 begin = offset - size
+            logging.log(self.loglevel, "LineBuffer.init: backward seek %d read %d" % (begin, size))
             file.seek(begin)
             lines = file.read(size).splitlines(True)
             if begin != 0:
@@ -83,6 +87,7 @@
         @param filename: name of the log file
         @param buffer_size: approx. size of one buffer in bytes
         """
+        self.loglevel = logging.NOTSET
         self.__filename = filename
         self.__buffer = None # currently used buffer, points to one of the following:
         self.__buffer1 = None
@@ -102,6 +107,7 @@
         self.to_end()
         while 1:
             try:
+                logging.log(self.loglevel, "LogFile.reverse %s" % self.__filename)
                 result = self.previous()
             except StopIteration:
                 return
@@ -205,6 +211,7 @@
         @return: True if moving more than to the beginning and moving
                  to the end or beyond
         """
+        logging.log(self.loglevel, "LogFile.peek %s" % self.__filename)
         self.__rel_index += lines
         while self.__rel_index < 0:
             if self.__buffer is self.__buffer2:
@@ -270,6 +277,7 @@
         result = None
         while result is None:
             while result is None:
+                logging.log(self.loglevel, "LogFile.next %s" % self.__filename)
                 result = self.__next()
             if self.filter and not self.filter(result):
                 result = None
@@ -289,6 +297,7 @@
         result = None
         while result is None:
             while result is None:
+                logging.log(self.loglevel, "LogFile.previous %s" % self.__filename)
                 result = self.__previous()
             if self.filter and not self.filter(result):
                 result = None
@@ -296,6 +305,7 @@
 
     def to_begin(self):
         """moves file position to the begin"""
+        logging.log(self.loglevel, "LogFile.to_begin %s" % self.__filename)
         if self.__buffer1 is None or self.__buffer1.offsets[0] != 0:
             self.__buffer1 = LineBuffer(self._input,
                                         0,
@@ -309,6 +319,7 @@
 
     def to_end(self):
         """moves file position to the end"""
+        logging.log(self.loglevel, "LogFile.to_end %s" % self.__filename)
         self._input.seek(0, 2) # to end of file
         size = self._input.tell()
         if self.__buffer2 is None or size > self.__buffer2.offsets[-1]:
@@ -339,6 +350,11 @@
         .seek is much more efficient for moving long distances than .peek.
         raises ValueError if position is invalid
         """
+        logging.log(self.loglevel, "LogFile.seek %s pos %d" % (self.__filename, position))
+        if self.__buffer1:
+            logging.log(self.loglevel, "b1 %r %r" % (self.__buffer1.offsets[0], self.__buffer1.offsets[-1]))
+        if self.__buffer2:
+            logging.log(self.loglevel, "b2 %r %r" % (self.__buffer2.offsets[0], self.__buffer2.offsets[-1]))
         if self.__buffer1 and self.__buffer1.offsets[0] <= position < self.__buffer1.offsets[-1]:
             # position is in .__buffer1 
             self.__rel_index = self.__buffer1.offsets.index(position)