1
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
2
# See LICENSE for details.
5
# -*- test-case-name: twisted.test.test_journal -*-
7
"""Logging that uses pickles.
9
TODO: add log that logs to a file.
13
from twisted.persisted import dirdbm
14
from twisted.internet import defer
15
from zope.interface import implements
22
"""Log pickles to DirDBM directory."""
24
implements(base.ICommandLog)
26
def __init__(self, logPath):
27
self.db = dirdbm.Shelf(logPath)
28
indexs = map(int, self.db.keys())
30
self.currentIndex = max(indexs)
34
def logCommand(self, command, time):
36
self.currentIndex += 1
37
self.db[str(self.currentIndex)] = (time, command)
38
return defer.succeed(1)
40
def getCurrentIndex(self):
41
"""Return index of last command logged."""
42
return self.currentIndex
44
def getCommandsSince(self, index):
46
for i in range(index, self.currentIndex + 1):
47
result.append(self.db[str(i)])