如何在多模块Maven项目中配置slf4j+logback?

发布于 2025-01-01 00:21:15 字数 159 浏览 6 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

默嘫て 2025-01-08 00:21:15

所有库 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 the slf4j-simple, it is simpler to use, and usually good enough for test cases.

自我难过 2025-01-08 00:21:15

假设您希望在带有 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文