I have a java project which uses log4j as a logger. The requirement is to have the test case name printed in the log file.
There are multiple tests in one class And the project supports parallel execution as well. A logger instance is created for each test.
I used system.Setproprty to associate my current logger instance with a the test case name. Following is my log4j.properties file :-
log4j.appender.logFileAppender.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss} [%t] ${testCaseName} %5p (%F:%L) - %m%n
log4j.appender.logFileAppender.Append=false
log4j.appender.logFileAppender.file=./log/UITest.log
And the runtime variable ${testCaseName} is set while creating a new instance of logger file as follows :-
public Logger log;
public synchronized Logger initializeLogger(String testName)
{
log = LoggerFactory.getLogger(testName);
System.setProperty("testCaseName", testName);
PropertyConfigurator.configure(log4jPropertiesFilePath);
return log;
}
The above looger instance creation method is called in a @BeforeMethod.
Currently the logger file is printing the test name of the last test in a class (In non-parallel ans parallel execution mode)
Kindly help me identify the issue due to which multiple test cases are not having their testcase name printed in the log file.