~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/testlogging.py

  • 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
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
 
2
# See LICENSE for details.
 
3
 
 
4
 
 
5
"""Test logging.
 
6
 
 
7
Message should only be printed second time around.
 
8
"""
 
9
 
 
10
from twisted.python import log
 
11
from twisted.internet import reactor
 
12
 
 
13
import sys, warnings
 
14
 
 
15
def test(i):
 
16
    print "printed", i
 
17
    log.msg("message %s" % i)
 
18
    warnings.warn("warning %s" % i)
 
19
    try:
 
20
        raise RuntimeError, "error %s" % i
 
21
    except:
 
22
        log.err()
 
23
 
 
24
def startlog():
 
25
    log.startLogging(sys.stdout)
 
26
 
 
27
def end():
 
28
    reactor.stop()
 
29
 
 
30
# pre-reactor run
 
31
test(1)
 
32
 
 
33
# after reactor run
 
34
reactor.callLater(0.1, test, 2)
 
35
reactor.callLater(0.2, startlog)
 
36
 
 
37
# after startLogging
 
38
reactor.callLater(0.3, test, 3)
 
39
reactor.callLater(0.4, end)
 
40
 
 
41
reactor.run()