scala Gatling - 在 Simulation.log 或控制台中记录请求正文
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33293588/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gatling - Log body of request in simulation.log or console
提问by namesake
I would like to see what is in the body of the post that I am sending in my script. In fact, I would like to see the request, request body and response. From looking at the docs and the forums, I see that I can uncomment a line in logback-test.xml which I did as shown below
我想看看我在脚本中发送的帖子正文中的内容。实际上,我想查看请求、请求正文和响应。通过查看文档和论坛,我看到我可以取消注释 logback-test.xml 中的一行,如下所示
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
<resetJUL>true</resetJUL>
</contextListener>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx</pattern>
<immediateFlush>false</immediateFlush>
</encoder>
</appender>
<!-- Uncomment for logging ALL HTTP request and responses -->
<logger name="io.gatling.http" level="TRACE" />
<!-- Uncomment for logging ONLY FAILED HTTP request and responses -->
<!--<logger name="io.gatling.http" level="DEBUG" /> -->
<root level="DEBUG">
<appender-ref ref="CONSOLE" />
</root>
The simulation.log file nor the console shows me the request, response etc. After a bit of googling and reading documentation, I saw that I could do this -
Simulation.log 文件和控制台都向我展示了请求、响应等。经过一些谷歌搜索和阅读文档后,我发现我可以做到这一点 -
.extraInfoExtractor(extraInfo => List(extraInfo.request, extraInfo.response,extraInfo.session))
This provides me with pretty much everything except the request body. How do I get the request body? I am trying to debug an issue where I am sure the body that is getting sent is not what I actually want.
这为我提供了除请求正文之外的几乎所有内容。如何获取请求正文?我正在尝试调试一个问题,我确定发送的正文不是我真正想要的。
回答by Bhushan Bhangale
Add this to your logback.xml
将此添加到您的 logback.xml
<logger name="io.gatling.http.ahc" level="DEBUG" />
This will print following details for each failure -
这将打印每个失败的以下详细信息 -
- Request url
- Request header
- Request body
- Response header
- Gatling session data
- 请求网址
- 请求头
- 请求正文
- 响应头
- 加特林会话数据
回答by Trying100
Uncommenting only TRACE and leaving DEBUG commented helped.
仅取消注释 TRACE 并留下 DEBUG 注释有帮助。
回答by dfostic
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx</pattern>
<immediateFlush>false</immediateFlush>
</encoder>
</appender>
<timestamp key="timestamp" datePattern="yyyy-MM-dd'T'HH:mm:ss"/>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>logs/test_${timestamp}.log</file>
<append>true</append>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx</pattern>
</encoder>
</appender>
<!-- TRACE logs all HTTP requests/response, DEBUG logs only failed HTTP requests/response-->
<logger name="io.gatling.http.engine.response" level="TRACE" />
<root level="INFO">
<appender-ref ref="FILE" />
<appender-ref ref="CONSOLE"/>
</root>

