# Not able to see logger messages in console while running tests

**URL:** <https://community.gatling.io/t/not-able-to-see-logger-messages-in-console-while-running-tests/8297>\
**Category:** Gatling (Open-Source)\
**Created:** [September 11, 2023, 10:53am UTC](https://community.gatling.io/t/not-able-to-see-logger-messages-in-console-while-running-tests/8297 "2023-09-11T10:53:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![harshit](https://avatars.discourse-cdn.com/v4/letter/h/c57346/32.png) [@harshit](https://community.gatling.io/u/harshit)\
**Post date:** [September 11, 2023, 10:53am UTC](https://community.gatling.io/t/not-able-to-see-logger-messages-in-console-while-running-tests/8297/1 "2023-09-11T10:53:44Z")

</div>

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

```scala
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
      })

```

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [September 11, 2023, 11:00am UTC](https://community.gatling.io/t/not-able-to-see-logger-messages-in-console-while-running-tests/8297/2 "2023-09-11T11:00:20Z")

</div>

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](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`.

---

<div class="post-metadata">

**Author:** ![harshit](https://avatars.discourse-cdn.com/v4/letter/h/c57346/32.png) [@harshit](https://community.gatling.io/u/harshit)\
**Post date:** [September 11, 2023, 11:09am UTC](https://community.gatling.io/t/not-able-to-see-logger-messages-in-console-while-running-tests/8297/3 "2023-09-11T11:09:23Z")

</div>

> [@slandelle](#):
>
> [https://github.com/gatling/gatling/blob/main/gatling-core/src/main/resources/logback.dummy#L11-L19](https://github.com/gatling/gatling/blob/main/gatling-core/src/main/resources/logback.dummy#L11-L19)

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

```auto
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:

```auto
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)))
}

```

---

<div class="post-metadata">

**Author:** ![sbrevet](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/sbrevet/32/830_2.png) [@sbrevet](https://community.gatling.io/u/sbrevet)\
**Post date:** [September 11, 2023, 11:26am UTC](https://community.gatling.io/t/not-able-to-see-logger-messages-in-console-while-running-tests/8297/4 "2023-09-11T11:26:32Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [September 11, 2023, 11:29am UTC](https://community.gatling.io/t/not-able-to-see-logger-messages-in-console-while-running-tests/8297/5 "2023-09-11T11:29:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![harshit](https://avatars.discourse-cdn.com/v4/letter/h/c57346/32.png) [@harshit](https://community.gatling.io/u/harshit)\
**Post date:** [September 11, 2023, 1:29pm UTC](https://community.gatling.io/t/not-able-to-see-logger-messages-in-console-while-running-tests/8297/6 "2023-09-11T13:29:50Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [September 11, 2023, 1:32pm UTC](https://community.gatling.io/t/not-able-to-see-logger-messages-in-console-while-running-tests/8297/7 "2023-09-11T13:32:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/2X/b/b148e0742de35c6280726cabf3ecd3de2d320f63.png) [@system](https://community.gatling.io/u/system)\
**Post date:** [October 11, 2023, 1:33pm UTC](https://community.gatling.io/t/not-able-to-see-logger-messages-in-console-while-running-tests/8297/8 "2023-10-11T13:33:14Z")

</div>

Closed on October 11, 2023, 1:33pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
