1 of 1 people found this helpful
Create an <appender> for each category, and within each <category> reference the corresponding appender using <appender-ref>. The log4j documentation should show you how to set this up.
This will give you a log file per category. You can always add additional catagories and appenders to split things out even more.
Personally, this seems like a whole lot of work for no good purpose. I could see that you might want all of the log entries for your code, which is probably using the same package prefix such as com.foo, to go into a separate log file. But I don't see any point to placing each class' log entries into a new log file. You will end up with hundreds of log files.
Thank you for your reply.
I've been looking for something easier, like setting a flag to tell the logger to create a new file per class, because as you say this approach of manually adding appenders for categories is over complicated.
The point of this is to have as many log-files as test classes so you get a test-report and a log-file per test-class. Not for production code.
Sorry, but there is no such flag in log4j. Though you might be able to extend one of the file appenders to provide this kind of functionality.