File: log.py

package info (click to toggle)
spyne 2.14.0-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,968 kB
  • sloc: python: 35,938; xml: 3,140; sh: 137; makefile: 135; ruby: 19
file content (56 lines) | stat: -rwxr-xr-x 1,256 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python

from __future__ import absolute_import

from spyne import Service, rpc, Application, Fault
from spyne.server.null import NullServer
from spyne.util.color import G


class SomeService(Service):
    @rpc()
    def server_exception(ctx):
        raise Exception("boo!")

    @rpc()
    def server_fault(ctx):
        raise Fault("Server", "boo and you know it!")

    @rpc()
    def client_fault(ctx):
        raise Fault("Client", "zzzz...")


server = NullServer(Application([SomeService], 'spyne.examples.logging'))


if __name__ == "__main__":
    import logging
    logging.basicConfig(level=logging.DEBUG)

    logging.info(G("all fault tracebacks are logged"))
    logging.getLogger('spyne.application').setLevel(logging.DEBUG)

    try:
        server.service.server_exception()
    except:
        pass
    try:
        server.service.server_fault()
    except:
        pass
    try:
        server.service.client_fault()
    except:
        pass

    logging.info(G("client fault tracebacks are hidden"))
    logging.getLogger('spyne.application.client').setLevel(logging.CRITICAL)
    try:
        server.service.server_fault()
    except:
        pass
    try:
        server.service.client_fault()
    except:
        pass