Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gatling - How to set gatling console log level in scala

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.

like image 981
kamal951 Avatar asked Apr 26 '18 08:04

kamal951


2 Answers

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"))
   ...
like image 145
djangofan Avatar answered Sep 28 '22 06:09

djangofan


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()
}
like image 41
kamal951 Avatar answered Sep 28 '22 08:09

kamal951