How to write log in jmeter?

In this article we are going to see functions of jmeter used for writing custom Log while running jmeter test. As, default log is stored in /bin/jmeter.log file, this will store in there.

There ate two functions are used for running custom jmeter logs. 

1. ${__log(StringForLogAndReturn,DEBUG,Text thrown,Comments)}
-It has 4 parameter
-it provides a string as output and logs the string
-The first parameter(StringForLogAndReturn) is only mandatory parameter. Text in here will be logged and return as function return. So, we can use this for console output also.
- 2nd parameter for LOG LEVEL, means which level of log will be written. There are
OUT , it will show log to command line(java System.out).
ERR ,it will show log to System.err(systems error log)
DEBUG , Only provides digging info(helpful for post/pre processors)
INFO, this is default log from jmeter
WARN or ERROR , Only warning messages
-3rd parameter is used to throw(like exception) a throw-able to the logger if it is non empty. That means, we can throw an exception along with log by this.
-4th parameter is comments. It is typical user comments.


2. ${__logn(StringForLogAndReturn,DEBUG,Text thrown)}
-It has 3 parameter
-it logs the string but provides an empty string.
- Like as __log, all parameters are same except it does not have comments as parameter.

Both are used in
-When we need to debug steps /requests/processing logs
-When we want to know detail information about what happened during execution
-When we are skipping all listeners and wan to see the errors(or our specific info) only
-When we want extracted information/parameters in the log(we can use variable inside every parameter)

Thanks...:)