Gatling - Log body of request in simulation.log or console
Asked Answered
N

6

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.

Now answered 23/10, 2015 at 1:46 Comment(0)
P
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
Prompt answered 13/2, 2016 at 14:45 Comment(2)
Weirdly I'm getting success requests being logged as wellParthena
DEBUG did not work for me, but TRACE did: <logger name="io.gatling.http.ahc" level="TRACE" />Instead
L
5
<?xml version="1.0" encoding="UTF-8"?>
<configuration>

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

</configuration>
Lipstick answered 10/4, 2019 at 14:6 Comment(3)
works for gatling 3. just edit the line <logger name="io.gatling.http.engine.response" level="TRACE" />Lipstick
This works for Gatling 3.6 in windows server to log in a fileCrouse
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)Friedly
P
2

Uncommenting only TRACE and leaving DEBUG commented helped.

Postexilian answered 19/4, 2017 at 19:59 Comment(0)
I
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.

Intestine answered 8/12, 2020 at 2:21 Comment(0)
B
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>
Breeden answered 8/9, 2020 at 13:32 Comment(2)
@Kozak, isn't that the same answer as provided by Bhushan Bhangale at https://mcmap.net/q/531660/-gatling-log-body-of-request-in-simulation-log-or-console?Forras
@TomerShetah No, there is an example with <root level="DEBUG"> <appender-ref ref="CONSOLE" /> </root> that is important and io.gatling.http.engine.responseBreeden
P
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>
Plastometer answered 15/4, 2021 at 10:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.