客户端 jar 中的 log4j.xml

发布于 2024-07-24 22:26:17 字数 189 浏览 2 评论 0原文

我有一些 jar 文件将分发给使用 log4j 进行日志记录的客户端。 我的问题是我应该在 jar 文件中包含 log4j.xml 配置,还是让客户端在需要日志记录时提供一个配置?

我的感觉是将 log4j.xml 配置文件留在客户端 jar 之外,因为 apache jar 文件都带有 log4j 日志记录,但没有 log4j.xml。

I have some jar files that will be distributed to clients that are using log4j for logging. My question is should I include a log4j.xml configuration in the jar file or have the client provide one if they want logging?

My feeling is to leave the log4j.xml configuration file out of the client jars, since the apache jar files all come with log4j logging, but sans log4j.xml.

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

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

发布评论

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

评论(5

忆悲凉 2024-07-31 22:26:17

是的,把它放在一边。 当您的 log4j 配置文件被忽略时,这是一件非常麻烦的事情,因为您的应用程序的 60 个第三方库之一包含自己的配置文件。

Yes, leave it out. It's an utter nuisance when your log4j configuration file is ignored because one of the 60 third-party libraries of your app contains its own.

热血少△年 2024-07-31 22:26:17

在您的情况下,log4j 的好处是您的 jar 确实不必担心它。 log4j 的基本用例是:

  1. 获取当前类的记录器对象
  2. 调用该记录器上的方法之一,例如 debug("some message");

如果您要传送的 jar 是由更大的应用程序使用,那么理想情况下您的代码将只执行上面列出的两个步骤。 这样,您的代码将简单地从客户端应用程序中已配置的 log4j 实例获取记录器对象。 然后,您的生产代码就不再需要知道如何配置 log4j。

开发 jar 时需要查看的任何日志记录都可以通过在单元测试 setUp() 方法中配置 log4j 实例或类似的方法来完成,这些方法不会与发送到客户端的生产代码捆绑在一起。

The good thing about log4j in your case is that your jar really shouldn't have to worry about it. The basic use case of log4j is:

  1. Obtain a logger object for the current class
  2. Call one of the methods on that logger, such as debug("some message");

If the jars you are shipping are to be used by a larger application, then ideally your code will only do the two steps listed above. In this way, your code will simply obtain logger objects from the already-configured log4j instance in the client's application. Your production code is then decoupled from having to know how to configure log4j.

Any logging you need to see for your development of the jars can be accomplished by configuring a log4j instance in unit test setUp() methods or something similar that won't get bundled with the production code going to the client.

心房的律动 2024-07-31 22:26:17

我会在文档中放置一个默认的 log4j 配置,您希望该配置对您的客户有用。 这样感兴趣的人就可以看到您有哪些日志记录选项(从用户的角度来看,通常某些类有更有趣的日志消息)。 当我有一个使用 log4j 的第三方库并且它没有文档,并且屏幕上充满日志消息时,我发现这很烦人,我必须尝试弄清楚如何启用或抑制某些日志消息。

I would put a default log4j configuration that you expect will be useful to your clients in the documentation. This way interested people can see what logging options you have (usually certain classes have more interesting log messages, from the user's perspective). I find it annoying when I have a third-party lib using log4j and it has no documentation, and there are log messages filling my screen and I have to try to figure out how to enable or suppress certain log messages.

不念旧人 2024-07-31 22:26:17

如果您在应用程序中使用 log4j,那么您可以将其包含在您的项目中。 如果不是的话,那你为什么要把它放在那里呢? 如果客户端 A 想要 log4j 版本 1.2,而客户端 B 想要 log4j 版本 1.3,该怎么办?

让他们决定他们的项目需要什么,并担心你的项目需要什么。

If you are using log4j in your application then you include it in your project. If you are not, then why would you put it in there? What if client A wants log4j version 1.2 and client B wants log4j version 1.3.

Let them decide what they need for their projects and worry about what you need for yours.

烟沫凡尘 2024-07-31 22:26:17

我将添加配置 xml 并加载它,并为用户显示不同的配置和选项的说明。 这将使他们或支持人员更容易启用附加日志记录。

I would add the configuration xml and load it up with instruction for the user showing different configuration and options. This will make it easier for either them or support to enable addition logging.

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