~ntt-pf-lab/nova/monkey_patch_notification

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/doc/core/examples/twistd-logging.tac

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Invoke this script with:
 
2
 
 
3
# $ twistd -ny twistd-logging.tac
 
4
 
 
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.
 
8
 
 
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
 
13
 
 
14
 
 
15
logfile = open("twistd-logging.log", "a")
 
16
 
 
17
 
 
18
def log(eventDict):
 
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)
 
23
 
 
24
 
 
25
def logSomething():
 
26
    msg("A log message")
 
27
 
 
28
 
 
29
LoopingCall(logSomething).start(1)
 
30
 
 
31
application = Application("twistd-logging")
 
32
application.setComponent(ILogObserver, log)
 
33