1
# Invoke this script with:
3
# $ twistd -ny twistd-logging.tac
5
# It will create a log file named "twistd-logging.log". The log file will
6
# be formatted such that each line contains the representation of the dict
7
# structure of each log message.
9
from twisted.application.service import Application
10
from twisted.python.log import ILogObserver, msg
11
from twisted.python.util import untilConcludes
12
from twisted.internet.task import LoopingCall
15
logfile = open("twistd-logging.log", "a")
19
# untilConcludes is necessary to retry the operation when the system call
20
# has been interrupted.
21
untilConcludes(logfile.write, "Got a log! %r\n" % eventDict)
22
untilConcludes(logfile.flush)
29
LoopingCall(logSomething).start(1)
31
application = Application("twistd-logging")
32
application.setComponent(ILogObserver, log)