| 1 |
# Copyright (c) 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 |
|
| 11 |
import sys |
| 12 |
import warnings |
| 13 |
|
| 14 |
from twisted.internet import reactor |
| 15 |
from twisted.python import log |
| 16 |
|
| 17 |
|
| 18 |
def test(i): |
| 19 |
print("printed", i) |
| 20 |
log.msg(f"message {i}") |
| 21 |
warnings.warn(f"warning {i}") |
| 22 |
try: |
| 23 |
raise RuntimeError(f"error {i}") |
| 24 |
except BaseException: |
| 25 |
log.err() |
| 26 |
|
| 27 |
|
| 28 |
def startlog(): |
| 29 |
log.startLogging(sys.stdout) |
| 30 |
|
| 31 |
|
| 32 |
def end(): |
| 33 |
reactor.stop() |
| 34 |
|
| 35 |
|
| 36 |
# pre-reactor run |
| 37 |
test(1) |
| 38 |
|
| 39 |
# after reactor run |
| 40 |
reactor.callLater(0.1, test, 2) |
| 41 |
reactor.callLater(0.2, startlog) |
| 42 |
|
| 43 |
# after startLogging |
| 44 |
reactor.callLater(0.3, test, 3) |
| 45 |
reactor.callLater(0.4, end) |
| 46 |
|
| 47 |
reactor.run() |