borgend/fifolog.py

Fri, 16 Feb 2018 23:25:30 +0000

author
Tuomo Valkonen <tuomov@iki.fi>
date
Fri, 16 Feb 2018 23:25:30 +0000
changeset 115
df0de44d2c4b
parent 89
51cc2e25af38
permissions
-rw-r--r--

Changed one .debug message to .info

#
# Borgend by Tuomo Valkonen, 2018
#
# This is a simple limited memory FIFO log for the logging module
#

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):(l-1)]

    def formatAll(self):
        return [self.format(record) for record in self.buffer]

mercurial