plone的结构化日志
ftw.structlog的Python项目详细描述
ftw.structlog
此包在plone中实现结构化请求登录。
它通过编写包含一个json条目的日志文件(每个实例一个)来实现 每行每一个请求。json条目包含 z2日志以结构化的键/值对提供了等等。
安装
- 安装ftw.structlog,方法是将其添加到构建中的鸡蛋列表中。 然后运行buildout并重新启动实例:
[instance]eggs += ftw.structlog
- 或者,将其作为依赖项添加到包的setup.py。
记录信息
示例条目:
{"bytes":6875,"cient_ip":"127.0.0.1","duration":0.30268411636353,"host":"127.0.0.1","method":"GET","referer":"http:\/\/localhost:8080\/plone","site":"plone","status":200,"timestamp":"2017-07-29T12:30:58.000750+02:00","url":"http:\/\/localhost:8080\/plone\/my-page","user":"john.doe","user_agent":"Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/60.0.3112.113 Safari\/537.36"}
记录的json条目包含以下数据:
key | value |
---|---|
bytes | Size of response body in bytes (^{tt3}$) |
client_ip | Host where the request originated from (respecting X-Forwarded-For) |
duration | Time spent in ZPublisher to handle request (time between ^{tt4}$ and ^{tt5}$ / ^{tt6}$ ) |
host | Deprecated. You should use ^{tt7}$ instead. |
method | HTTP request method |
referer | Referer |
site | Plone site ID |
status | HTTP response status |
timestamp | Time when request was received (non-naive local time in ISO 8601, in the server’s local timezone as determined by ^{tt8}$) |
url | URL of the request (including query string if present) |
user | Username of the authenticated user, ^{tt9}$ otherwise |
user_agent | User-Agent |
日志文件位置
将为每个zope2实例创建一个日志文件,以及它的位置和名称 将从实例的事件日志路径派生。如果实例的事件日志 路径是var/log/instance2.log,json日志文件的路径是 var/log/instance2-json.log。
注意:因为ftw.structlog从 事件日志路径,必须在zope.conf中配置事件日志,否则 ftw.structlog不会记录任何请求并大声抱怨 根记录器。
在其他项目中运行测试时,可以通过设置 环境变量FTW_STRUCTLOG_MUTE_SETUP_ERRORS=true。
链接
更改日志
1.1.0(2019-01-11)
- 已弃用:host字段已弃用。相反,新引进的 client_ip字段应用于获取客户端的IP地址。 [lgraf]
- 总是将丢失的referer记录为空字符串,而不是null。 [lgraf]
1.0.1(2017-09-03)
- 如果找不到事件日志配置以派生 从中记录位置。不是阻止实例启动,而是记录 使用根记录器时出现明显的错误消息。 [lgraf]
1.0.0(2017-09-03)
- 初步实施 [lgraf]