-
1. Re: Log file using class name
peterj Aug 31, 2011 11:48 AM (in response to iapazmino)1 of 1 people found this helpfulCreate 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.
-
2. Re: Log file using class name
iapazmino Sep 1, 2011 4:56 PM (in response to peterj)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.
-
3. Re: Log file using class name
peterj Sep 1, 2011 5:51 PM (in response to iapazmino)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.