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

前端 未结 5 2349
我寻月下人不归
我寻月下人不归 2021-02-19 00:28

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

相关标签:
5条回答
  • 2021-02-19 00:33

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

    0 讨论(0)
  • 2021-02-19 00:37

    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>
    
    0 讨论(0)
  • 2021-02-19 00:47

    Uncommenting only TRACE and leaving DEBUG commented helped.

    0 讨论(0)
  • 2021-02-19 00:56

    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.

    0 讨论(0)
  • 2021-02-19 00:58

    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
    0 讨论(0)
提交回复
热议问题