borgend/fifolog.py

Wed, 14 Feb 2018 15:23:39 +0000

author
Tuomo Valkonen <tuomov@iki.fi>
date
Wed, 14 Feb 2018 15:23:39 +0000
changeset 114
ad9fb3dd9fec
parent 89
51cc2e25af38
permissions
-rw-r--r--

Disable Notification Centre notifications.
They don't work reliably for some reason, and are in any case annoying
unless the display is somehow fine-tuned.

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