25

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

<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 -

.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.

kdabir
  • 9,623
  • 3
  • 43
  • 45
namesake
  • 325
  • 1
  • 4
  • 8

6 Answers6

22

Add this to your logback.xml

<logger name="io.gatling.http.ahc" level="DEBUG" />

This will print following details for each failure -

  1. Request url
  2. Request header
  3. Request body
  4. Response header
  5. Gatling session data
Bhushan Bhangale
  • 10,921
  • 5
  • 43
  • 71
5

<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>

dfostic
  • 1,608
  • 15
  • 8
  • 2
    works for gatling 3. just edit the line `` – dfostic Apr 10 '19 at 14:06
  • This works for Gatling 3.6 in windows server to log in a file – vinilpj Nov 02 '21 at 12:30
  • I tired this but log file is not getting created on the fly is there any thing else needs to be done. ch.qos.logback.core.FileAppender[FILE] - openFile(logs/app_2022-01-06T16:06:11.log,false) call failed. java.io.FileNotFoundException: logs\app_2022-01-06T16:06:11.log (The filename, directory name, or volume label syntax is incorrect) – Lusitha Jan 06 '22 at 10:34
2

Uncommenting only TRACE and leaving DEBUG commented helped.

Trying100
  • 21
  • 1
1

An update with Gatling 3.x, the comment in logback.xml is quite self-explain

<!-- uncomment and set to DEBUG to log all failing HTTP requests -->
<!-- uncomment and set to TRACE to log all HTTP requests -->
<!-- <logger name="io.gatling.http.engine.response" level="TRACE" />-->

After uncomment the above config we can get the request url, request header, response etc in the log or IDE'S console. That's very helpful to verify the dynamic feeder value used in request url or body, and it's the way to debug the failed requests.

Eric Tan
  • 1,377
  • 15
  • 14
0

Just choose the root level as DEBUG

<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
        <pattern>%d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx</pattern>
    </encoder>
    <immediateFlush>false</immediateFlush>
</appender>

<logger name="io.gatling.http.engine.response" level="DEBUG" />

<root level="DEBUG">
    <appender-ref ref="CONSOLE" />
</root>
Ilonyna
  • 1
  • 2
  • @Kozak, isn't that the same answer as provided by Bhushan Bhangale at https://stackoverflow.com/a/35381270/2359227? – Tomer Shetah Sep 09 '20 at 05:32
  • 1
    @TomerShetah No, there is an example with that is important and io.gatling.http.engine.response – Ilonyna Sep 09 '20 at 09:09
0

If you want to see logging of all HTTP requests and responses plus Session contents in your console output you can do the following:

  1. Add or uncomment the following lines in your logger file:
<logger name="io.gatling.http.ahc" level="TRACE" />
<logger name="io.gatling.http.response" level="TRACE" />
  1. Set root level as TRACE:
<root level="TRACE">
    <appender-ref ref="CONSOLE" />
</root>
Alex Green
  • 488
  • 4
  • 8