Using Log4J 1.x, you will have to manually create a Logger instance in each class, providing a unique file name for each test, using a combination of the set name and class name (assuming each set has a unique name).
For example, in the setUp() method of the test class, specify the log file name:
String logFilename = context.getSuite().getName() + "_" + this.getClass().getSimpleName();
Then, in each class used by the test, manually create a logger instance and specify the name of the log file that you want to use:
public class SomeClass { private Logger log = null; public SomeClass(String logFilename) { log = Logger.getLogger(logFilename); }
But this solution is not very elegant, it requires passing the file name to all the classes used in the test.
The best decision:
If you can upgrade to Log4J 2, it supports writing to separate log files using ThreadContext : http://logging.apache.org/log4j/2.x/faq.html#separate_log_files
I also found this blog post suggesting to use LOGBack and its contextual diagnostic context: http://www.nullin.com/2010/07/28/logging-tests-to-separate-files/
source share