fifolog.py

changeset 34
9fce700d42de
child 35
495a510a6d01
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/fifolog.py	Sun Jan 21 16:21:53 2018 +0000
@@ -0,0 +1,18 @@
+#
+# FIFO memory logger
+#
+
+from logging.handlers import BufferingHandler
+
+class FIFOHandler(BufferingHandler):
+    def shouldFlush(self, record):
+        return False
+
+    def emit(self, record):
+        self.buffer.append(record)
+        l=len(self.buffer)
+        if l>self.capacity:
+            self.buffer=self.buffer[(l-self.capacity+1):l]
+
+    def formatAll(self):
+        return [self.format(record) for record in self.buffer]

mercurial