Request Logging for WSGI Web Applications
-----------------------------------------
This is a middleware which you can use to log requests to your WSGI
based site. It's even imitating Apache's combined log format to allow
you to use any of the many tools for Apache log file analysis.
By making use of Python's standard library logging facilities, you can
easily set it up to log to STDOUT, time rotated log files, email,
syslog, etc.
Installation
^^^^^^^^^^^^
Simply install this Python module via
::
pip install wsgi-request-logger
Usage
^^^^^
To add this middleware to your WSGI ``application`` and log to the file
*access.log*, do:
::
from requestlogger import WSGILogger, ApacheFormatter
from logging.handlers import TimedRotatingFileHandler
def application(environ, start_response):
response_body = 'The request method was %s' % environ['REQUEST_METHOD']
response_body = response_body.encode('utf-8')
response_headers = [('Content-Type', 'text/plain'),
('Content-Length', str(len(response_body)))]
start_response('200 OK', response_headers)
return [response_body]
handlers = [ TimedRotatingFileHandler('access.log', 'd', 7) , ]
loggingapp = WSGILogger(application, handlers, ApacheFormatter())
if __name__ == '__main__':
from wsgiref.simple_server import make_server
http = make_server('', 8080, loggingapp)
http.serve_forever()
The Authors
^^^^^^^^^^^
This WSGI middleware was originally developed under the name
`wsgilog <https://pypi.python.org/pypi/wsgilog/>`__ by **L. C. Rees**.
It was forked by **Philipp Klaus** in 2013 to build a WSGI middleware
for request logging rather than exception handling and logging.
License
^^^^^^^
This software, *wsgi-request-logger*, is published under a *3-clause BSD
license*.
Developers' Resources
^^^^^^^^^^^^^^^^^^^^^
- To read about your options for the logging handler, you may want to
read `Python's Logging
Cookbook <http://docs.python.org/3/howto/logging-cookbook.html>`__.
- Documentation on Apache's log format can be found
`here <http://httpd.apache.org/docs/current/mod/mod_log_config.html#logformat>`__.
- The
`WSGI <http://en.wikipedia.org/wiki/Web_Server_Gateway_Interface>`__
- Web Server Gateway Interface - is defined in `PEP
333 <http://www.python.org/dev/peps/pep-0333/>`__ with an update for
Python 3 in `PEP 3333 <http://www.python.org/dev/peps/pep-3333/>`__.
General References
^^^^^^^^^^^^^^^^^^
- PyPI's `listing of
wsgi-request-logger <https://pypi.python.org/pypi/wsgi-request-logger>`__
- The source code for this Python module is `hosted on
Github <https://github.com/pklaus/wsgi-request-logger>`__.
- A blog post with more background information and usage examples:
`wsgi-request-logger – Logging HTTP Requests With Any WSGI Web
Application like Flask, Bottle or
Django <https://blog.philippklaus.de/2013/06/wsgi-request-logger-logging-http-requests-with-any-wsgi-web-application-like-flask-bottle-or-django/>`__
Raw data
{
"_id": null,
"home_page": "https://github.com/pklaus/wsgi-request-logger",
"name": "wsgi-request-logger",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "WSGI Apache-like request logging",
"author": "Philipp Klaus",
"author_email": "philipp.l.klaus@web.de",
"download_url": "https://files.pythonhosted.org/packages/04/dd/5e6c52b96a841baec75e5c5647460214aa02e9c4902c7b250375352224c0/wsgi-request-logger-0.4.6.tar.gz",
"platform": "any",
"description": "Request Logging for WSGI Web Applications\n-----------------------------------------\n\nThis is a middleware which you can use to log requests to your WSGI\nbased site. It's even imitating Apache's combined log format to allow\nyou to use any of the many tools for Apache log file analysis.\n\nBy making use of Python's standard library logging facilities, you can\neasily set it up to log to STDOUT, time rotated log files, email,\nsyslog, etc.\n\nInstallation\n^^^^^^^^^^^^\n\nSimply install this Python module via\n\n::\n\n pip install wsgi-request-logger\n\nUsage\n^^^^^\n\nTo add this middleware to your WSGI ``application`` and log to the file\n*access.log*, do:\n\n::\n\n from requestlogger import WSGILogger, ApacheFormatter\n from logging.handlers import TimedRotatingFileHandler\n\n def application(environ, start_response):\n response_body = 'The request method was %s' % environ['REQUEST_METHOD']\n response_body = response_body.encode('utf-8')\n response_headers = [('Content-Type', 'text/plain'),\n ('Content-Length', str(len(response_body)))]\n start_response('200 OK', response_headers)\n return [response_body]\n\n handlers = [ TimedRotatingFileHandler('access.log', 'd', 7) , ]\n loggingapp = WSGILogger(application, handlers, ApacheFormatter())\n\n if __name__ == '__main__':\n from wsgiref.simple_server import make_server\n http = make_server('', 8080, loggingapp)\n http.serve_forever()\n\nThe Authors\n^^^^^^^^^^^\n\nThis WSGI middleware was originally developed under the name\n`wsgilog <https://pypi.python.org/pypi/wsgilog/>`__ by **L. C. Rees**.\nIt was forked by **Philipp Klaus** in 2013 to build a WSGI middleware\nfor request logging rather than exception handling and logging.\n\nLicense\n^^^^^^^\n\nThis software, *wsgi-request-logger*, is published under a *3-clause BSD\nlicense*.\n\nDevelopers' Resources\n^^^^^^^^^^^^^^^^^^^^^\n\n- To read about your options for the logging handler, you may want to\n read `Python's Logging\n Cookbook <http://docs.python.org/3/howto/logging-cookbook.html>`__.\n- Documentation on Apache's log format can be found\n `here <http://httpd.apache.org/docs/current/mod/mod_log_config.html#logformat>`__.\n- The\n `WSGI <http://en.wikipedia.org/wiki/Web_Server_Gateway_Interface>`__\n - Web Server Gateway Interface - is defined in `PEP\n 333 <http://www.python.org/dev/peps/pep-0333/>`__ with an update for\n Python 3 in `PEP 3333 <http://www.python.org/dev/peps/pep-3333/>`__.\n\nGeneral References\n^^^^^^^^^^^^^^^^^^\n\n- PyPI's `listing of\n wsgi-request-logger <https://pypi.python.org/pypi/wsgi-request-logger>`__\n- The source code for this Python module is `hosted on\n Github <https://github.com/pklaus/wsgi-request-logger>`__.\n- A blog post with more background information and usage examples:\n `wsgi-request-logger \u2013 Logging HTTP Requests With Any WSGI Web\n Application like Flask, Bottle or\n Django <https://blog.philippklaus.de/2013/06/wsgi-request-logger-logging-http-requests-with-any-wsgi-web-application-like-flask-bottle-or-django/>`__",
"bugtrack_url": null,
"license": "BSD",
"summary": "Apache-like combined logging for WSGI Web Applications",
"version": "0.4.6",
"project_urls": {
"Download": "UNKNOWN",
"Homepage": "https://github.com/pklaus/wsgi-request-logger"
},
"split_keywords": [
"wsgi",
"apache-like",
"request",
"logging"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "04dd5e6c52b96a841baec75e5c5647460214aa02e9c4902c7b250375352224c0",
"md5": "0e2fd4a5b676f34238de12a621368f24",
"sha256": "445d7ec52799562f812006394d0b4a7064b37084c6ea6bd74ea7a2136c97ed83"
},
"downloads": -1,
"filename": "wsgi-request-logger-0.4.6.tar.gz",
"has_sig": false,
"md5_digest": "0e2fd4a5b676f34238de12a621368f24",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4380,
"upload_time": "2016-10-08T09:13:56",
"upload_time_iso_8601": "2016-10-08T09:13:56.631820Z",
"url": "https://files.pythonhosted.org/packages/04/dd/5e6c52b96a841baec75e5c5647460214aa02e9c4902c7b250375352224c0/wsgi-request-logger-0.4.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2016-10-08 09:13:56",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "pklaus",
"github_project": "wsgi-request-logger",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "wsgi-request-logger"
}