如何集中日志配置,并仅使用 log4j.properties?

发布于 2024-10-01 00:05:54 字数 183 浏览 1 评论 0原文

我想使用 log4j.properties 在我的应用程序中配置日志记录,并指示(以某种方式)所有第三方包/模块通过此配置进行日志记录。现在它们的日志记录不同,而且一团糟:OpenEJB、Hibernate、Apache HttpClient、Jersey 等。我该怎么做?我只想使用 log4j

I would like to configure logging in my application with log4j.properties and instruct (somehow) all third-party packages/modules to log through this configuration. Now they log differently and it's a mess: OpenEJB, Hibernate, Apache HttpClient, Jersey, etc. How can I do this? I want to work with log4j only.

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

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

发布评论

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

评论(1

梦断已成空 2024-10-08 00:05:54

使用可以将各种日志框架重定向到 log4j 的框架:slf4j

有关概述,请参阅“桥接旧版 API”。

[编辑] slf4j 的 Maven pom.xml

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.6.1</version>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>1.6.1</version>
</dependency>
<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <version>1.2.16</version>
  <!-- The usual exclusions here: javax.mail:mail, oro:oro -->
</dependency>

Use a framework which can redirect all kinds of logging frameworks to log4j: slf4j.

See "Bridging legacy APIs" for an overview.

[Edit] Maven pom.xml for slf4j:

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.6.1</version>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>1.6.1</version>
</dependency>
<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <version>1.2.16</version>
  <!-- The usual exclusions here: javax.mail:mail, oro:oro -->
</dependency>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文