Package wsgiwapi :: Module logging
[frames] | no frames]

Source Code for Module wsgiwapi.logging

 1  # Copyright (c) 2009 Richard Boulton 
 2  # 
 3  # Permission is hereby granted, free of charge, to any person obtaining a copy 
 4  # of this software and associated documentation files (the "Software"), to deal 
 5  # in the Software without restriction, including without limitation the rights 
 6  # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
 7  # copies of the Software, and to permit persons to whom the Software is 
 8  # furnished to do so, subject to the following conditions: 
 9  # 
10  # The above copyright notice and this permission notice shall be included in 
11  # all copies or substantial portions of the Software. 
12  # 
13  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
14  # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
15  # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
16  # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
17  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
18  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
19  # SOFTWARE. 
20  r"""Logging support for WSGIWAPI. 
21   
22  """ 
23  __docformat__ = "restructuredtext en" 
24   
25  import time 
26  import traceback 
27   
28 -class StdoutLogger(object):
29 """Logger which writes messages to stdout. 30 31 """
32 - def request_start(self, environ):
33 return time.time()
34
35 - def request_end(self, environ, start_value, request, response):
36 elapsed = time.time() - start_value 37 print("%f(%f):%s %r %s" % (start_value, elapsed, 38 request.method, request.path, 39 response.response.status) 40 )
41
42 - def request_failed(self, environ, start_value, exc_info):
43 elapsed = time.time() - start_value 44 traceback.print_exception(*exc_info) 45 print("%f(%f):ERROR %r %s" % (start_value, elapsed, 46 environ.get('PATH_INFO', ''), 47 str(exc_info[1])) 48 )
49
50 -class SilentLogger(object):
51 """Logger which produces no output. 52 53 """
54 - def request_start(self, environ):
55 pass
56 - def request_end(self, environ, start_value, request, response):
57 pass
58 - def request_failed(self, environ, start_value, exc_info):
59 pass
60
61 -class VerboseLogger(object):
62 """Logger which writes verbose messages to stdout. 63 64 """
65 - def request_start(self, environ):
66 print ("%f:START:%s %s" % (time.time(), 67 environ.get('REQUEST_METHOD'), 68 environ.get('PATH_INFO')) 69 ) 70 return time.time()
71
72 - def request_end(self, environ, start_value, request, response):
73 now = time.time() 74 elapsed = now - start_value 75 print ("%f(%f):DONE:%s %r %s" % (now, elapsed, 76 request.method, request.path, 77 response.response.status) 78 )
79
80 - def request_failed(self, environ, start_value, exc_info):
81 now = time.time() 82 elapsed = now - start_value 83 traceback.print_exception(*exc_info) 84 print ("%f(%f):ERROR %r %s" % (now, elapsed, 85 environ.get('PATH_INFO', ''), 86 str(exc_info[1])) 87 )
88 89 # vim: set fileencoding=utf-8 : 90