spring、hibernate、log4j 用于集中错误捕获
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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.
log4j.jar
inWEB-INF/lib
log4j.properties
and place in on the root of your classpathprivate static final Logger log = Logger.getLogger(CurrentClass.class);
如果您想要集中日志记录,并且由于您正在使用 Spring 和 Hibernate,那么事情会比仅仅提供
log4j.properties
更复杂一些,因为 Hibernate 使用 SLF4J 作为日志记录外观,而 Spring 使用 SLF4J 作为日志记录外观使用 Jakarta Commons Logging (JCL) 作为日志外观,它们似乎存在冲突。我的建议是使用 SLF4J,为此,您需要:
jcl-over-slf4j.jar
以桥接 JCL 调用到 SLF4J 为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:
slf4j-api.jar
(you should actually get this one with Hibernate)commons-logging.jar
that comes from Springjcl-over-slf4j.jar
to bridge JCL calls to SLF4Jslf4j-log4j12.jar
) to bridge SLF4J calls to Log4Jlog4j.jar
See also