将 log4j.properties 捆绑在库中 - 风格不好还是什么?

发布于 2024-11-27 23:48:16 字数 449 浏览 3 评论 0原文

我遇到了一个不错的小型 Java Web 请求框架:Spark。该 API 看起来不错并且很有前途,但库包本身却很奇怪。更不用说它建议使用快照工件作为依赖项这一事实。更不用说它使用 log4j 进行日志记录(现在库倾向于使用 jcl 或 slf4j),有时还使用 System.out.println。但它在spark-xxx.jar 中捆绑了自己的log4j.properties。我花了一个小时来调查为什么当 log4j.properties 确实存在于我的类路径中时我的项目会抱怨 log4j 配置。 -Dlog4j.debug=true给出了答案,log4j承认它已经从spark jar加载了log4j.properties。

我想知道这(作为一个库并使用 log4j 和捆绑 log4j.properties)是否有一些动机,或者它是否只是蹩脚。

I came across a nice small web request framework for Java: Spark. The API looks nice and promising, but the library bundle itself is pretty strange. Leave alone the fact that it proposes using snapshot artifacts as dependencies. Leave alone the fact that it uses log4j for logging (libraries tend to use jcl or slf4j nowadays), and System.out.println sometimes. But it bundles its own log4j.properties in spark-xxx.jar. It took me an hour to investigate why my project would complain of log4j configuration when log4j.properties is definitely present in my classpath. -Dlog4j.debug=true gave the answer, log4j confessed that it had loaded log4j.properties from spark jar.

I wonder if this (being a library and using log4j and bundling log4j.properties) has some motivation, or if it is just lame.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

月亮邮递员 2024-12-04 23:48:16

将 log4j.properties 与库捆绑在一起是不好的风格。

使用 Spark,您可能会认为它更接近应用程序服务器(如 Tomcat),在这种情况下它可以配置日志记录。

我想说的测试是,控制 start(.sh|.bat) 脚本的人应该配置日志记录,并且 log4j 配置文件几乎不应该位于 jar 中。

It is bad style to bundle a log4j.properties with a library.

With spark you could argue that it is closer to an app server (like tomcat) in which case it could configure logging.

I would say the test is that whoever controls the start(.sh|.bat) script should configure logging, and that log4j config files should almost never be in a jar.

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