add in timing log (bug 635644)

This commit is contained in:
Andy McKay 2011-02-22 10:32:22 -08:00
Родитель e917639574
Коммит 4148b2e846
2 изменённых файлов: 13 добавлений и 2 удалений

Просмотреть файл

@ -8,6 +8,7 @@ from urlparse import parse_qsl
import MySQLdb as mysql
import sqlalchemy.pool as pool
import commonware.log
import settings_local as settings
@ -55,6 +56,9 @@ bad_rdf = """<?xml version="1.0"?>
</RDF:RDF>"""
timing_log = commonware.log.getLogger('z.timer')
def getconn():
db = settings.SERVICES_DATABASE
return mysql.connect(host=db['HOST'], user=db['USER'],
@ -262,7 +266,6 @@ def mail_exception(data):
msg['To'] = settings.ADMINS
msg['From'] = settings.DEFAULT_FROM_EMAIL
conn = smtplib.SMTP(settings.EMAIL_HOST, settings.EMAIL_PORT)
conn.sendmail(settings.DEFAULT_FROM_EMAIL, settings.ADMINS,
msg.as_string())
@ -270,13 +273,20 @@ def mail_exception(data):
def application(environ, start_response):
start = time()
status = '200 OK'
timing = (environ['REQUEST_METHOD'], '%s?%s' %
(environ['SCRIPT_NAME'], environ['QUERY_STRING']))
data = dict(parse_qsl(environ['QUERY_STRING']))
try:
update = Update(data)
output = update.get_rdf()
start_response(status, update.get_headers(len(output)))
except:
timing_log.info('%s "%s" (500) %.2f [ANON]' %
(timing[0], timing[1], time() - start))
mail_exception(data)
raise
timing_log.info('%s "%s" (200) %.2f [ANON]' %
(timing[0], timing[1], time() - start))
return output

Просмотреть файл

@ -2,7 +2,8 @@ import os
import site
wsgidir = os.path.dirname(__file__)
for path in ['../', '../..', '../../vendor/src/django', '../../lib',
for path in ['../', '../..', '../../vendor/src/commonware',
'../../vendor/src/django', '../../lib',
'../../vendor/lib/python', '../../apps/versions']:
site.addsitedir(os.path.abspath(os.path.join(wsgidir, path)))