File: testlogging.py

package info (click to toggle)
twisted 12.0.0-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 9,720 kB
  • sloc: python: 78,364; ansic: 179; makefile: 113; sh: 34
file content (41 lines) | stat: -rw-r--r-- 714 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.


"""Test logging.

Message should only be printed second time around.
"""

from twisted.python import log
from twisted.internet import reactor

import sys, warnings

def test(i):
    print "printed", i
    log.msg("message %s" % i)
    warnings.warn("warning %s" % i)
    try:
        raise RuntimeError, "error %s" % i
    except:
        log.err()

def startlog():
    log.startLogging(sys.stdout)

def end():
    reactor.stop()

# pre-reactor run
test(1)

# after reactor run
reactor.callLater(0.1, test, 2)
reactor.callLater(0.2, startlog)

# after startLogging
reactor.callLater(0.3, test, 3)
reactor.callLater(0.4, end)

reactor.run()