如何在多模块Maven项目中配置slf4j+logback?
我的 Maven 项目大约有七个子模块。其中 6 个打包为 JAR,1 个打包为 WAR。
我应该在每个模块中创建单独的 logback.xml 配置吗?或者我应该有一个所有其他模块都依赖的“通用”模块,并在其中放置一个 logback.xml ?还有其他选择吗?
谢谢。
My Maven project has about seven sub-modules. Six of them packages as JARs and one as WAR.
Should I create individual logback.xml config in each module? Or should I have a "common" module that all other modules depend on, and put one single logback.xml in there? Are there any other options?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所有库 JAR 都应仅使用 slf4j-api 依赖项,并且只有最终应用程序(在您的情况下为
.war
)应包含 logback 依赖项及其配置。出于测试目的,我认为更容易使
test
依赖于slf4j-simple
,它使用起来更简单,通常足以进行测试案例。All library JARs should use only slf4j-api dependency, and only a final application (in your case it is
.war
) should contain logback dependency and its configuration.For test purposes I think easier to make
<scope>test</scope>
dependency to theslf4j-simple
, it is simpler to use, and usually good enough for test cases.假设您希望在带有 jar 打包的模块中添加 logback.xml 配置文件用于测试目的,则只需将 logback.xml 放置在每个“jar”类型模块的
src/test/resources
文件夹下即可。正如@kan提到的,slf4j绑定,例如slf4j-simple或logback-classic,应该在测试范围内。
Assuming you wish to add logback.xml configuration file in the modules with jar packaging for testing purposes, then just place logback.xml under
src/test/resources
folder in each module of type 'jar'.As @kan mentioned, the slf4j binding, e.g. slf4j-simple or logback-classic, should be in the test scope.