log4j in a multi-module Maven project

半城伤御伤魂 提交于 2019-12-12 12:18:26

问题


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.



来源:https://stackoverflow.com/questions/13767911/log4j-in-a-multi-module-maven-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!