Log4j file appender for each instance of a class
-
23-12-2019 - |
Question
I have a scenario class, which has list of Test cases. Is there any way that I can save each Test case execution to separate file with name: TestCaseName.log
?
I have done this before with java.util.logging
by adding file handler in the code, but have no idea how to do this with Log4j.
Solution 2
Task was completed by adding RollingFileAppenders programmatically, just like in this example: http://howtodoinjava.com/2013/04/08/how-to-programmatically-configure-appenders-in-log4j/
OTHER TIPS
You can do this by configuring a separate org.apache.log4j.RollingFileAppender
for each Test case class.
You can check the link http://logging.apache.org/log4j/2.x/manual/configuration.html for configuring this.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow