borgend/fifolog.py

Mon, 07 Feb 2022 11:38:54 +0200

author
Tuomo Valkonen <tuomov@iki.fi>
date
Mon, 07 Feb 2022 11:38:54 +0200
changeset 145
2e8b9a3caa56
parent 89
51cc2e25af38
permissions
-rw-r--r--

py2app has problems with relative paths, so revert them

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