Gatling - How to set gatling console log level in scala
Asked Answered
I

3

5

I have created a maven project that will generate a jar file with all my simulations in it and when I run it, the console log level is too high. There is too much unusefull informations for me. Is there a way to configure it in the code ? Here is my code:

import io.gatling.app.Gatling
import io.gatling.core.config.GatlingPropertiesBuilder 
import io.gatling.core.config.GatlingConfiguration

object Engine extends App {
    val props = new GatlingPropertiesBuilder
    if(System.getProperty("resultsFolder") == null){
      props.resultsDirectory("results")
    }else{
      props.resultsDirectory(System.getProperty("resultsFolder"))
    }

    props.dataDirectory("data")
      props.simulationClass(System.getProperty("simulationClass"))

    Gatling.fromMap(props.build)
  sys.exit()
}

And here is the tree of my directory:

¦   dependency-reduced-pom.xml
¦   pom.xml
¦
+---src
    +---main
    ¦   +---resources
    ¦   +---scala
    ¦       +---myPackage
    ¦                   ¦   Engine.scala
    ¦                   ¦
    ¦                   +---simulation
    ¦                           BasicSimulation.scala
    ¦
    +---test
        +---resources
        ¦       application.conf
        ¦       gatling.conf
        ¦       logback-test.xml
        ¦
        +---scala
                Placeholder.scala

The .config files and logback are the default ones of Gatling.

Iodic answered 26/4, 2018 at 8:37 Comment(0)
B
7

Here is how you do it:

package gatling.simulations

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
import org.slf4j.LoggerFactory
import ch.qos.logback.classic.{Level, LoggerContext}

class FooSimulation extends Simulation {

  val context: LoggerContext = LoggerFactory.getILoggerFactory.asInstanceOf[LoggerContext]
  // Log all HTTP requests
  context.getLogger("io.gatling.http").setLevel(Level.valueOf("TRACE"))
  // Log failed HTTP requests
  //context.getLogger("io.gatling.http").setLevel(Level.valueOf("DEBUG"))
   ...
Bowling answered 9/11, 2018 at 0:41 Comment(0)
I
1

I have found a solution: put the log level in the Engine instead of reaing the logbaxk.xml file:

import io.gatling.app.Gatling
import io.gatling.core.config.GatlingPropertiesBuilder 
import io.gatling.core.config.GatlingConfiguration
import org.slf4j.LoggerFactory
import java.util.logging.{Level, Logger}

object Engine extends App {
 LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME).asInstanceOf[Logger].setLevel(Level.WARNING)
    val props = new GatlingPropertiesBuilder
    if(System.getProperty("resultsFolder") == null){
      props.resultsDirectory("results")
    }else{
      props.resultsDirectory(System.getProperty("resultsFolder"))
    }

    props.dataDirectory("data")
      props.simulationClass(System.getProperty("simulationClass"))

    Gatling.fromMap(props.build)
  sys.exit()
}
Iodic answered 26/4, 2018 at 9:12 Comment(0)
D
0

I run my gatling like : mvn clean gatling:execute@slalom -DLOG_LEVEL=WARN

Replace WARN with any other level and it will be displayed as such.

The LOG_LEVEL then gets replaced directly in the logback-test.xml during compilation as follows:

<?xml version="1.0" encoding="UTF-8"?>

<properties>
    <LOG_LEVEL>WARN</LOG_LEVEL>
</properties>

<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="${LOG_LEVEL}" default = "WARN"/>
<!-- Uncomment for logging ONLY FAILED HTTP request and responses -->
<!--<logger name="io.gatling.http" level="WARN" />-->

<root level="${LOG_LEVEL}" default="WARN">
    <appender-ref ref="CONSOLE" />
</root>
-->

Dowden answered 2/5, 2018 at 12:53 Comment(1)
but the short answer is, change in this file logback-test.xml , this part <root level="${LOG_LEVEL}" default="WARN"> <appender-ref ref="CONSOLE" /> </root>Dowden

© 2022 - 2024 — McMap. All rights reserved.