Log4j - Logging to multiple log files based on the project modules

Posted by Veera on Stack Overflow See other posts from Stack Overflow or by Veera
Published on 2010-05-28T07:17:20Z Indexed on 2010/05/28 7:21 UTC
Read the original article Hit count: 290

Filed under:
|
|

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. :)

© Stack Overflow or respective owner

Related posts about java

Related posts about logging