Not able to see logger messages in console while running tests

I am running the tests using mvn gatling:test
But I am not able to log the message using logger.info

Here is my logback-test.xml file

<?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>
        </encoder>
        <immediateFlush>false</immediateFlush>
    </appender>

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

    <root level="INFO">
        <appender-ref ref="CONSOLE"/>
    </root>

</configuration>

This is where I have logged the info message

def getAuthToken() =
    exec(
      http("POST OAuth Req")
        .get("Our URL")
        .headers(authorization2)
        .check(status.in(200, 401))
        .check(status.saveAs("statusCode"))
        .check(bodyString.saveAs("access"))
    )
      .exec(session => {
        val statusCode = session("statusCode").as[Int]
        if (statusCode == 401) {
//          println("Received 401 Unauthorized error")
          logger.info("This is an info message.")
        }
        token = session("access").as[String]
        session
      })

Several things

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

This was for Gatling 2. Please use the correct loggers, see https://github.com/gatling/gatling/blob/main/gatling-core/src/main/resources/logback.dummy#L11-L19

logger.info("This is an info message.")

Is this logger an slf4j one? If so, the only reason for it to not get displayed in that statusCode is not 401.

Thanks I updated it but still info message is not getting displayed. I even removed the if check of status code with 401

def getAuthToken() =
    exec(
      http("POST OAuth Req")
        .get("our url")
        .headers(authorization2)
        .check(status.in(200, 401))
        .check(status.saveAs("statusCode"))
        .check(bodyString.saveAs("access"))
    )
      .exec(session => {
        val statusCode = session("statusCode").as[Int]
        logger.info("This is an info message.")
        token = session("access").as[String]
        session
      })

Some more info, I used

import org.slf4j.LoggerFactory

Simulation file:

class expensesSimulation extends Simulation {
val expensesScenario = scenario("Expenses - Scenario")
    .during(Configuration.duration) {
      exitBlockOnFail(
        group ("load-test") {
          exec(
            pace(Configuration.paceFrom,Configuration.paceTo),
            feed(expenseIds), feed(expenseAttendeeIds)
            .exec(
              expensesChain.getAuthToken()
            )
          )
	}
      )
    }
  val sleepDuration = Configuration.warmupDuration + Configuration.ramp + Configuration.ramp

setUp(
 expensesScenario.inject(nothingFor(sleepDuration seconds),rampUsers(Configuration.users) during(Configuration.ramp seconds)))
}

Hi @harshit,

Where is your logback-test.xml file located? I guess in src/test/resources, isn’t it?

Did you try a mvn clean after your modification and retry the mvn gatling:test?
Did you try renaming the file to logback.xml?

Cheers!

exitBlockOnFail(

Pretty sure that a request fails before the virtual user can reach the place where you have to log, causing it to immediately exit and never reach this point.

I changed the file name to logback.xml
The file is located at src/test/performance/resources
Is there a way I can change the default path?

Doh, this is a very bad idea. Why not stick to the standard convention instead of looking for trouble?