Wed, 07 Feb 2018 20:39:01 +0000
Time snapshot fixes.
Python's default arguments are purely idiotic (aka. pythonic): generated
only once. This makes sense in a purely functional language, which Python
lightyears away from, but severely limits their usefulness in an imperative
language. Decorators also seem clumsy for this, as one would have to tell
the number of positional arguments for things to work nice, being able to
pass the snapshot both positionally and as keyword. No luck.
So have to do things the old-fashioned hard way.
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 | 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] |