log4j在多模块Maven项目中 [英] log4j in a multi-module Maven project

查看:642
本文介绍了log4j在多模块Maven项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在多模块Maven项目中实现log4j?我是否将log4j.properties文件添加到每个子模块的src / main / resources目录中?如果是这样,我是否必须为每个文件追加器指定不同的输出文件?或者有没有办法为整个项目提供一个总体log4j.properties文件,而没有配置噩梦。哪种方法(许多log4j.properties文件与一个)更常见,更好的做法?感谢您提前获得所有反馈。

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.

推荐答案

这取决于您打算如何部署和运行此项目。对于分层多模块项目,我们通常在模块中包含一个log4j配置文件,其中包含 main 方法,该方法将启动该程序。

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.

例如,考虑使用项目 client server 的简化设置,它们都依赖于 framework 用于公共类(RMI接口,域对象等)。客户端作为桌面应用程序运行,具有自己的入口点,因此在src / main / resources下获取自己的log4j.properties文件。服务器模块也是如此。然而,框架获取属性文件 - 其记录器调用将由其调用模块配置的任何记录器处理。

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.

这篇关于log4j在多模块Maven项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆