类apache的wsgi web应用程序组合日志
wsgi-request-logger的Python项目详细描述
这是一个中间件,您可以使用它将请求记录到您的wsgi 基地。它甚至模仿了apache的组合日志格式来允许 您可以使用许多用于apache日志文件分析的工具中的任何一个。
通过使用python的标准库日志记录工具,您可以 轻松设置日志到标准输出,时间轮换日志文件,电子邮件, 系统日志等
安装
只需通过
pip install wsgi-request-logger
用法
将此中间件添加到wsgiapplication并登录到文件 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()
许可证
此软件wsgi request logger是在3子句bsd下发布的 许可证。
开发商资源
- 要阅读日志处理程序的选项,您可能需要 阅读Python’s Logging Cookbook。
- 可以找到有关apache日志格式的文档 here。
- 那个 WSGI -web服务器网关接口-在PEP 333中定义,并更新 Python3在PEP 3333。
一般参考
- PYPI的listing of wsgi-request-logger
- 这个python模块的源代码是hosted on Github。
- 包含更多背景信息和使用示例的博客文章: wsgi-request-logger – Logging HTTP Requests With Any WSGI Web Application like Flask, Bottle or Django