borgend/fifolog.py

Tue, 21 Apr 2020 09:59:51 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Tue, 21 Apr 2020 09:59:51 -0500
changeset 129
9f3ae6b3133f
parent 89
51cc2e25af38
permissions
-rw-r--r--

Improve installation instructions;
move py2app to keychain configuration section.

34
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1 #
89
51cc2e25af38 Added author information headers and content information to source files
Tuomo Valkonen <tuomov@iki.fi>
parents: 80
diff changeset
2 # Borgend by Tuomo Valkonen, 2018
51cc2e25af38 Added author information headers and content information to source files
Tuomo Valkonen <tuomov@iki.fi>
parents: 80
diff changeset
3 #
51cc2e25af38 Added author information headers and content information to source files
Tuomo Valkonen <tuomov@iki.fi>
parents: 80
diff changeset
4 # This is a simple limited memory FIFO log for the logging module
34
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
5 #
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
6
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
7 from logging.handlers import BufferingHandler
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
8
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
9 class FIFOHandler(BufferingHandler):
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
10 def shouldFlush(self, record):
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
11 return False
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
12
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
13 def emit(self, record):
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
14 self.buffer.append(record)
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
15 l=len(self.buffer)
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
16 if l>self.capacity:
35
495a510a6d01 Python indexes from zero...
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
17 self.buffer=self.buffer[(l-self.capacity):(l-1)]
34
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
18
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
19 def formatAll(self):
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
20 return [self.format(record) for record in self.buffer]

mercurial