buffer log messages

This commit is contained in:
Michael Davidsaver
2013-12-10 16:06:56 -05:00
parent 46f997b9a9
commit 146021b546

View File

@ -9,7 +9,7 @@ import inotifyy as inot
from devsup.hooks import addHook from devsup.hooks import addHook
from devsup.util import StoppableThread from devsup.util import StoppableThread
from devsup.db import IOScanListBlock from devsup.db import IOScanListThread
mask=inot.IN_CREATE|inot.IN_DELETE|inot.IN_MOVED_FROM|inot.IN_MODIFY mask=inot.IN_CREATE|inot.IN_DELETE|inot.IN_MOVED_FROM|inot.IN_MODIFY
@ -25,25 +25,24 @@ class LogWatcher(StoppableThread):
self.IN = inot.INotify() self.IN = inot.INotify()
self.dirwatch = self.IN.add(self.event, dir, mask) self.dirwatch = self.IN.add(self.event, dir, mask)
self.scan = IOScanListBlock() self.scan = IOScanListThread()
self.allowScan = self.scan.add self.allowScan = self.scan.add
addHook('AfterIocRunning', self.start) addHook('AfterIocRunning', self.start)
addHook('AtIocExit', self.join) addHook('AtIocExit', self.join)
self.arr = rec.field('VAL').getarray() self.arr = rec.field('VAL').getarray()
print('arr',self.arr.dtype)
self.fd = None self.fd = None
self.buf = None
self.msg = ""
print(rec, 'will watch', self.fname) print(rec, 'will watch', self.fname)
def detach(self, rec): def detach(self, rec):
pass pass
def process(self, rec, reason): def process(self, rec, reason=None):
buf = np.frombuffer(self.msg, dtype=self.arr.dtype) if reason is None:
return
buf = np.frombuffer(reason, dtype=self.arr.dtype)
buf = buf[:rec.NELM-1] buf = buf[:rec.NELM-1]
self.arr[:buf.size] = buf self.arr[:buf.size] = buf
self.arr[buf.size] = 0 self.arr[buf.size] = 0
@ -59,6 +58,7 @@ class LogWatcher(StoppableThread):
def run(self): def run(self):
print("log watcher staring",self.fname) print("log watcher staring",self.fname)
self.log("Starting")
self.openfile() self.openfile()
self.catfile() self.catfile()
self.IN.loop() self.IN.loop()
@ -116,7 +116,6 @@ class LogWatcher(StoppableThread):
self.log(L[:-1]) # Skip newline self.log(L[:-1]) # Skip newline
def log(self, msg): def log(self, msg):
self.msg = msg self.scan.interrupt(reason=msg)
self.scan.interrupt()
build = LogWatcher build = LogWatcher