Consider this scenario:
I have a project with two modules and one common module as below (the package structure):
com.mysite.moduleone
com.mysite.moduletwo
com.mysite.commonmodule
In the above, the commonmodule
classes can be used by other two modules.
The question:
I need to configureLog4J such a way that the log messages from moduleone
and moduletwo
goes to different log file. I can always do this using using category.
But the real problem is when I want to log the messages from the commonmodule
also. So, when the commonmodule
classes are called from moduleone
the commonmodule
log messages should go to the moduleone
log file. If the commonmodule
is accesse from moduletwo
the commonmodule
log messages should go to moduletwo
log file.
Is it possible to configure Log4J in this fashion? Any comments?
PS: I think I made my question clear. If any confusion, leave a comment, wil try to clear it. :)
Is it possible to configure Log4J in this fashion?
In short, it is not with log4j unless you write a custom filter. And that filter would need to capture and analyse the call stack for each log event that makes it to each log appender ... which would be expensive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With