微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Cherrypy logingg POST 正文

如何解决Cherrypy logingg POST 正文

我正在使用认的cherrypy 记录器。 我已经记录了对我的服务器的每个访问请求。对于 GET 请求,我有完整的信息,比如

- command: "{{ item }}"
  loop:
    - "ls" 
    - "df -h"
  register: files

- command: "{{ item }}"
  loop:
    - "ls -lrt" 
    - "du -h"
  register: files1      

- lineinfile:
    line: "{{ item.stdout }}"
    path: /home/ubuntu/log/list.log
    create: yes
  loop: 
    - "{{ files.results }}"
    - "{{ files1.results }}"
  delegate_to: localhost

但是对于 POST 请求,我无法记录查询参数或正文。

127.0.0.1 - - [06/Jul/2021:16:10:28] "GET /test/?contract_id=228322 HTTP/1.0" 200 33

那么我如何记录 POST 查询的正文?

解决方法

您可以创建类似的工具

def response_logging():
    cherrypy.log.access_log.info(
        '[{time}] {ip} "{user_agent}" {request_line} "{query_params}" "{body}" "{status}" {response}'.format(
            time=datetime.now().strftime("%d/%m/%Y:%H:%M:%S"),ip=cherrypy.request.remote.ip,user_agent=cherrypy.request.headers["User-Agent"],request_line=cherrypy.request.request_line,query_params=cherrypy.request.body.request_params or "",body=cherrypy.request.json if hasattr(cherrypy.request,"json") else "",status=cherrypy.response.status,response=cherrypy.response.body
        )
    )


cherrypy.tools.response_logging = cherrypy.Tool('on_end_request',response_logging)
,
print(cherrypy.request.params) # Prints params on querystring
print(cherrypy.request.headers) # Prints received headers on request
print(cherrypy.request.body) # Prints Body received

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?