fifolog.py

Sun, 28 Jan 2018 11:01:45 +0000

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sun, 28 Jan 2018 11:01:45 +0000
changeset 77
e8773133bf79
parent 35
495a510a6d01
permissions
-rw-r--r--

DreamTime.monotonic() no longer needs to call time.monotonic()
so is more "static" within wakeup periods, and so comparable to
time.monotonic() realisations. Also some PyObjC weirdness handling.

34
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1 #
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
2 # FIFO memory logger
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
3 #
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
4
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
5 from logging.handlers import BufferingHandler
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 class FIFOHandler(BufferingHandler):
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
8 def shouldFlush(self, record):
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
9 return False
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
10
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
11 def emit(self, record):
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
12 self.buffer.append(record)
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
13 l=len(self.buffer)
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
14 if l>self.capacity:
35
495a510a6d01 Python indexes from zero...
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
15 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
16
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
17 def formatAll(self):
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
18 return [self.format(record) for record in self.buffer]

mercurial