Skip to content

Commit

Permalink
0.11.0 - Adds preliminary logging support
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich Jones committed Feb 19, 2016
1 parent f9128e8 commit 0d9d710
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ requests>=2.9.1
six==1.10.0
tqdm==3.7.1
wheel==0.24.0
wsgi-request-logger==0.4.4
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

setup(
name='zappa',
version='0.10.4',
version='0.11.0',
packages=['zappa'],
install_requires=required,
include_package_data=True,
Expand Down
23 changes: 23 additions & 0 deletions zappa/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import logging

from urllib import urlencode
from requestlogger import ApacheFormatter
from StringIO import StringIO

def create_wsgi_request(event_info, server_name='zappa', script_name=None,
Expand Down Expand Up @@ -65,3 +68,23 @@ def create_wsgi_request(event_info, server_name='zappa', script_name=None,
environ['PATH_INFO'].replace(script_name, '')

return environ

def common_log(environ, response, response_time=None):
"""
Given the WSGI environ and the response,
log this event in Common Log Format.
"""

logger = logging.getLogger()
logger.setLevel(logging.INFO)

if response_time:
formatter = ApacheFormatter(with_response_time=True)
else:
formatter = ApacheFormatter(with_response_time=False)

log_entry = formatter(response.status_code, environ, len(response.content), rt_ms=response_time)
logger.info(log_entry)

return

0 comments on commit 0d9d710

Please sign in to comment.