How to use log4j write logs into a mysql database on Jmeter? - log4j

Jmeter default write logs into a file named "jmeter.log".But there is a file named "log4j.conf" under the folder "bin". I confused about how to use it. Anyone can help me ?

please check in the conf
# JMeter does not use log4j as logging system
# This configuration will only be used by libraries that do use log4j
# or your custom code if it uses it
# For logging configuration of JMeter, it needs to be done in user.properties
how it works.
If you have special sampler that uses java code .. in that java code if you use log.info , log.error, log.warn statements it prints that to jmeter.log Hope this helps
If you have jsr223 groovy sampler try putting below line and check jmeter.log you see the logging info.
log.info "check this in jmeter.log"
Hope this helps ..

Related

How to change log.info/error message's font color in Jmeter's JSR223?

I'm trying to find a way to change log.info/error message's font color so that it would be easier for me to read messages in Jmeter's JSR223 Log section
any advice ?
thanks,
As per current version (JMeter 4.0) I don't think it is possible. You can use Groovy Coloriser library if you want, however it will only work for println statements, not for JMeter's log.error
The only way you can filter out the log output to errors only is configuring JMeter logging subsystem to display only messages of ERROR level (or above). You can do this in at least 2 ways:
Locate <Root level="info"> line in log4j2.xml file (lives in "bin" folder of your JMeter installation) and change info to error. JMeter restart will be required to pick the property up
Or you can simply run JMeter like jmeter -LERROR
In both cases you will not be seeing all these INFO and/or WARN messages anymore, you will see only ERROR and above.
More information:
Overriding Properties Via The Command Line
How to Configure JMeter Logging

How to clear the consul in jmeter - using groovy

I have a question about the printing that I perform in Jmeter, I use
System.out.println and the consul is full with data.
the problem is that if I want in each iteration to clear the consul how can I do it?
the consul is full with data from last run, or Prev thread and I just want to clear it.
regards (it is the black consul that opened in a new window.)
You should log messages using log.info("Hello World"); (log is a script global variable) instead of using OUT in your scripts. Therefore, the logs will be sent to jmeter.log file.
See the documentation about JSR223 Sampler for more information.
For Windows you can use something like:
new ProcessBuilder('cmd', '/c', 'cls').inheritIO().start().waitFor()
For other operating system it will depend on SHELL implementation, you will need to amend the command line according to your requirements, most likely using clear command.
References:
ProcessBuilder documentation
Groovy is the New Black

How can I change the name and location of log4j.properties?

How can I change the name of log4j.properties and the location of this as well?
You can change its location like so:
java -Dlog4j.configuration=file:/path_to_file_here/log4j.properties YourApplication
You should also read the manual.
Regarding changing the name, this is how you can achieve this:
First, you must add the following line to your java runtime command:
-Dlog4j.configuration=test.properties
For example lets assume you are using log4j in your web application deployed on Tomcat.
Add the above mentioned line in the java runtime command to start up Tomcat:
C:\Tools\java\j2sdk1.4.2_01\bin\java.exe -jar
-Duser.dir="C:\Tools\Tomcat 4.1"
-Dlog4j.configuration=test.properties
-Djava.endorsed.dirs="C:\Tools\Tomcat 4.1\common\endorsed"
"C:\Tools\Tomcat 4.1\bin\bootstrap.jar" start
You will also possibly want to read this.
I know this is a really old post, but the first thread when I searched for the question. And my found solution is:
System.setProperty("log4j.configurationFile", "theNameIWant.properties");

How to read a txt file, get a data and store it as variable in Custom Properties of SOAPUI using Groovy?

i started to use Soapui this week and i did some tests like sending a request POST and save the response as txt file ina folder.
What i'm trying to do is to read this txt file, copy a sepcific data and store it in Custom Properties.
Because i want to use this object in the nest Request POST which is depending of the first request.
I want to do it in Groovy.
i have only the Open source SOAPUI version 5.0.0
Thank you
You've to add a groovy test step in your test case and do it similar as you would in java, check groovy documentation.
Only as a reference SOAPUI 5.2.0 has the groovy 2.1.7 version (check the dependency in pom.xml) so in groovy scripts which runs on SOAPUI you can use the java standard api included in the jre, the SOAPUI classes, the groovy 2.1.7 API among some others, additionally you can include other jars in SOAPUI\bin\ext in order to use them in groovy script.
Finally you're asking about to read some data from a file and write it to a custom property, so for example you can do it as follows:
// read the file from path
def file = new File('/path/yourFile')
// for example read line by line
def yourData = file.eachLine { line ->
// check if the line contains your data
if(line.contains('mySpecifiyData=')){
return line
}
}
// put the line in a custom property in the testCase
testRunner.testCase.setPropertyValue('yourProp',yourData)
Since your problem it's not clear I show you a possible sample showing how to read a file looking for specific content and saving this content in a custom property in the testCase.
Note that in groovy scripts the are a global objects which you can use: testRunner, context and log, in this sample I use testRunner to access testCase and its properties, in the same way you can go thought testRunner to access testSuites, project, testSteps etc... check the documentation:
http://www.soapui.org/Scripting-Properties/tips-a-tricks.html
http://www.soapui.org/Functional-Testing/working-with-scripts.html
Hope this helps,

BSF Assertion from script file does not load UDVs

I am trying to use groovy scripts as BSF assertion in JMeter. The script written inside the JMETER assertion script box works well, but when I try to use it through a groovy file it is not loading the User Defined Variables it needs for assertions
It says
org.apache.bsf.BSFException: exception from Groovy: groovy.lang.MissingPropertyException: No such property: mobileNumber class: D__RESTAPITesting_JmeterBSFAssertionScripts_Script1
Not sure why it is looking for property when ${..} refers to a variable (if I am not wrong). Any help on the error message and how to use a script file for assertions ?
The scripts I have written are saved as *.groovy. Do I need to save scripts in some other extensions for BSF to read it correctly ?
Pass your User Defined Variables via Parameters input like ${foo} ${bar}
In your .groovy script body refer variables as args[0] args[1]
See image below for details (the solution works fine for file inputs as well) and How to Use JMeter Assertions in 3 Easy Steps guide for advanced information on using JMeter's assertions.

Resources