spring、hibernate、log4j 用于集中错误捕获

发布于 2024-09-08 07:43:32 字数 70 浏览 2 评论 0原文

我正在使用 JSF 2.0、Spring、Hibernate,并且我需要实现 Log4J 来进行集中错误捕获。有人可以帮忙吗?

I am using JSF 2.0, Spring, Hibernate and I need to implement Log4J for centralized error catching. Can anybody help?

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

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

发布评论

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

评论(2

面犯桃花 2024-09-15 07:43:33

log4j 与 spring、jsf 或 hibernate 完全无关。

  • log4j.jar 放入 WEB-INF/lib
  • 获取样本 log4j.properties 并将其放在类路径的根目录中,
  • 使用 私有静态最终Logger log = Logger.getLogger(CurrentClass.class);

log4j has absolutely nothing to do with spring, jsf or hibernate.

  • place log4j.jar in WEB-INF/lib
  • get a sampel log4j.properties and place in on the root of your classpath
  • use private static final Logger log = Logger.getLogger(CurrentClass.class);
泪之魂 2024-09-15 07:43:32

如果您想要集中日志记录,并且由于您正在使用 Spring 和 Hibernate,那么事情会比仅仅提供 log4j.properties 更复杂一些,因为 Hibernate 使用 SLF4J 作为日志记录外观,而 Spring 使用 SLF4J 作为日志记录外观使用 Jakarta Commons Logging (JCL) 作为日志外观,它们似乎存在冲突

我的建议是使用 SLF4J,为此,您需要:

  • 提供 slf4j-api.jar(您实际上应该使用 Hibernate 获取此文件)
  • 删除 commons-logging.jar<来自 Spring 的 /code>
  • 提供 jcl-over-slf4j.jar 以桥接 JCL 调用到 SLF4J 为
  • Log4J (slf4j-log4j12.jar) 提供 SLF4J 绑定以桥接SLF4J 对 Log4J 的调用
  • 提供 log4j.jar

另请参阅

If you want centralized logging and since you are using Spring and Hibernate, things are a bit more complicated than just providing a log4j.properties because Hibernate uses SLF4J as logging facade while Spring uses Jakarta Commons Logging (JCL) as logging facade and they seem to conflict.

My recommendation would be to use SLF4J and for that, you'll need to:

  • provide slf4j-api.jar (you should actually get this one with Hibernate)
  • remove commons-logging.jar that comes from Spring
  • provide jcl-over-slf4j.jar to bridge JCL calls to SLF4J
  • provide the SLF4J binding for Log4J (slf4j-log4j12.jar) to bridge SLF4J calls to Log4J
  • provide log4j.jar

See also

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