Hi All,
Greetings!!
I want to write captured regex results from HTTP responses to an external file. I already referred to this link (https://groups.google.com/forum/#!topic/gatling/hpUECuX9Fc4) but not able to find a correct syntax. Also I already have TRACE method enabled in logback.xml (attached the logback.xml with this message) it is working fine but since the HTTP responses are really huge , I just want to save specific values within HTTP response to a external file.
For now I am using the below code to write to a file I knew this is not threadsafe and does not support concurrency,
.exec( session => {
val fout = new FileWriter(“CartID.log”, true)
val fileout = new PrintWriter(new BufferedWriter(fout))
fileout.print(session( “cartID” ).as[String])
fileout.println()
fileout.close()
session})
I got to know that slf4j is a better method that supports concurrency, in this link https://groups.google.com/forum/#!topic/gatling/hpUECuX9Fc4 there is a small piece of code showing slf4j implementation within a scala file but that does not seem to work with latest version of Gatling even after importing the following slf4j packages . Looking forward to this forum to help me get away from this issue.
import org.slf4j.Logger._
import org.slf4j.LoggerFactory._
Regards,
Shobitha
logback.xml (1.24 KB)
In addition to my previous message, I get the below given error messages when trying to compile the following code
val logger = org.slf4j.LoggerFactory.getLogger(this.getClass)
.exec { session => logger.debug(session(“versionNum”).as[String]);
session }
or
val logger = org.slf4j.LoggerFactory.getLogger(“myDebugLogger”)
.exec(session => {
logger.debug(session.getAttribute(“versionNum”))
session})
Compilation errors:
value exec is not a member of org.slf4j.Logger
possible cause: maybe a semicolon is missing before `value exec’?
21926 [main] ERROR io.gatling.compiler.ZincCompiler$ - .exec(session => {
recursive value logger needs type
22158 [main] ERROR io.gatling.compiler.ZincCompiler$ - .exec { session => logger.debug(session(“versionNum”).as[String]);
Hi All,
I was able to successfully implement Slf4j logger in my Gatling script. I browsed through http://www.slf4j.org/manual.html#binding and got the needed solution,
This is how I did the implementation of slf4j,
Following statements should be added to the scala file,
import org.slf4j.Logger._
import org.slf4j.LoggerFactory._
then I added following block of statement to my scala file,
.exec(session => {
val logger = org.slf4j.LoggerFactory.getLogger(this.getClass)
logger.info("The version number is ********************************************* ")
logger.info(session (“versionNum”).as[String])
session})
In addition to this, please ensure you add slf4j-api-1.7.13.jar to your system class path.