How do I implement log4j in a multi-module Maven project? Do I add a "log4j.properties" file to the src/main/resources directory of every submodule? If so, do I have to specify a different output file for each file appender? Or is there a way to have one overarching log4j.properties file for the whole project, without having a configuration nightmare. Which approach (many log4j.properties files versus one) is more common and better practice? Thanks for all feedback in advance.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
It depends on how you intend to deploy and run this project. For hierarchical multi-module projects, we generally included a log4j config file in the module with the main
method that would launch the program.
For example, consider a simplified setup with projects client
and server
which both rely on framework
for common classes (RMI interfaces, domain objects, etc). Client is run as a desktop application, has its own main
entry point, and thus gets its own log4j.properties file under src/main/resources. So does the server module. Framework, however, does not get a properties file -- its logger calls will be handled by whichever loggers have been configured by its calling module.