您可以检查每一个Django请求的Python时间、SQL时间和查询计数。
django-actionlog的Python项目详细描述
开始
django操作可以检查每个请求的python时间、sql时间和查询计数 对于django框架。结果将日志输出到文件、控制台或fluentd。
要求
django actionlog要求django 1.6或更高版本
fluent logger 0.4.1或更高版本
得到它
您可以使用pip或easy_install获得django操作日志:
$ pip install django-actionlog or $ easy_install django-actionlog
如果要从源代码安装,请从github获取git存储库并运行setup.py:
$ git clone git://github.com/fujimisakari/django-actionlog.git $ cd django-actionlog $ python setup.py install
安装它
要在项目中启用django-actionlog
,需要将其添加到项目中的MIDDLEWARE_CLASSES
和ACTION_LOG_SETTING
settings.py
文件:
MIDDLEWARE = [ ... 'django_actionlog.middleware.ActionLogMiddleware', ... ] # Action Log ACTION_LOG_SETTING = {'handler_type': 'stdout'}
使用它
输出runserver控制台的情况
ACTION_LOG_SETTING = {'handler_type': 'stdout'}
输出文件大小写
# default logfile: `/tmp/django_action.log` ACTION_LOG_SETTING = {'handler_type': 'file', 'logfile': '/tmp/my_action.log'}
输出fluentd的情况
# default host: `localhost` # default port: `24224` # default tag_name: `django.actionlog` ACTION_LOG_SETTING = {'handler_type': 'fluentd', 'host': 'example.com', 'tag_name': 'my_service.foo'}
想要输出自定义操作日志的情况
from django_actionlog import actionlog ... actionlog.output({'foo': 'bar', 'fizz': 'buzz'...}) ...