What i want to do is to run JMeter in non-GUI mode and get a logfile for every single sampler, not just the entire testcase. Is there a way to accomplish that?
I'm using v3.2
Add Beanshell Listener at end of your Thread Group and put this script:
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.net.URLDecoder;
import org.apache.jmeter.services.FileServer;
String samplerNumber = "${__threadNum}";
String samplerName = "${__samplerName()}";
if(sampleEvent.getResult() instanceof org.apache.jmeter.protocol.http.sampler.HTTPSampleResult) {
String request = (sampleEvent.getResult().getSamplerData());
String response = prev.getResponseDataAsString();
f = new FileOutputStream("/home/username/logs/myJMeterLog.log", true);
p = new PrintStream(f);
//EDIT:
p.println("Thread: " + samplerNumber + ", sampler name: " + samplerName + ", system time: " + new Date() +"\nREQUEST: " + java.net.URLDecoder.decode(request, "UTF-8") + "\nRESPONSE: " + response + "\n\n");
p.close();
f.close();
}
You can modify it to meet your requirements. It will log every HTTP request data to given log file. You can also name log file as some thread specific variable (e.g. username) to have separate logs for each thread. Hope this helps...
Another answer (for this add one Counter - config element to HTTP sampler and put counter as reference name):
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.net.URLDecoder;
import org.apache.jmeter.services.FileServer;
String samplerName = "${__samplerName()}";
if(sampleEvent.getResult() instanceof org.apache.jmeter.protocol.http.sampler.HTTPSampleResult) {
f = new FileOutputStream("/home/username/logs/" + samplerName +.log", true);
p = new PrintStream(f);
p.println("Request: " + java.net.URLDecoder.decode(request, "UTF-8") + ", sample time: " + prev.getTime() + ", sample count: " + String.valueOf(vars.get("counter")));
p.close();
f.close();
}