borgend/fifolog.py

Mon, 29 Jan 2018 09:38:53 +0000

author
Tuomo Valkonen <tuomov@iki.fi>
date
Mon, 29 Jan 2018 09:38:53 +0000
changeset 89
51cc2e25af38
parent 80
a409242121d5
permissions
-rw-r--r--

Added author information headers and content information to source files

#
# 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