--- a/fixbot/logwatch/sources.py Thu Feb 04 20:14:22 2010 +0200
+++ b/fixbot/logwatch/sources.py Thu Feb 04 20:39:53 2010 +0200
@@ -1,10 +1,23 @@
-from twisted.internet import reactor, protocol
+"""
+ Implementations of the various sources of log data
+"""
+
+from twisted.internet import protocol
from twisted.python import log
from fixbot import fifo
class LogSource (object) :
+ """
+ Reads lines of log data from some file or other source.
+ """
+
def __init__ (self, name, filters) :
+ """
+ name - label lines read from this source
+ filters - LogFilter chain to pass lines through
+ """
+
# set later on
self.module = None
@@ -25,6 +38,10 @@
self.module.error(msg)
def handleData (self, data) :
+ """
+ Buffer the given chunk of data, passing any full lines to handleLine
+ """
+
data = self.buf + data
while "\n" in data :
@@ -42,20 +59,30 @@
out = filter.test(line)
if out :
+ # unpack
+ type, msg = out
+
# positive match, send
- log.msg("\t%s: %s" % (filter.event_type, out))
- self.module.sendEvent(filter.event_type, out)
-
+ log.msg("\t%s: %s" % (type, msg))
+
+ # drop until we have a module
+ if self.module :
+ self.module.sendEvent(type, msg)
+
+ # ok, first hit does it
break
elif out is False :
# negative match, stop processing
return
- else : # None
+ elif out is None :
# no match
continue
+ else :
+ raise ValueError(out)
+
class File (LogSource, protocol.ProcessProtocol) :
"""
Stream lines from a regular file using /usr/bin/tail -f