java EclipseLink 和 log4j:如何同时使用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7970480/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
EclipseLink and log4j: how to use both
提问by javagirl
I'm using Eclipselink JPA provider, and noticed that it writes in console only. I configured both the console and file appenders, but EclipseLink log entries (SQL queries for example) are appeared only in the console log. How to fix it?
我正在使用 Eclipselink JPA 提供程序,并注意到它仅在控制台中写入。我配置了控制台和文件附加程序,但 EclipseLink 日志条目(例如 SQL 查询)仅出现在控制台日志中。如何解决?
Here is my log4j configuration:
这是我的 log4j 配置:
log4j.rootLogger=ALL, FILE, CONSOLE
log4j.logger.uk.co.mycompany=DEBUG
log4j.logger.org.eclipse.persistence=ALL
log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.FILE.File=${catalina.base}/logs/application.log
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{HH:mm:ss, SSS} %t [%p] %c{1} - %m%n
# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{HH:mm:ss,SSS} [%p] %m%ne
In the persistence.xml:
在persistence.xml 中:
...
<properties>
<property name="eclipselink.logging.level" value="FINE"/>
</properties>
回答by orien
Eclipse Link doesn't use log4j by default. This page describes how you can integrate it:
Eclipse Link 默认不使用 log4j。此页面描述了如何集成它:
回答by gamliela
Make sure you initialize EclipseLink logging facilities (by doing some action that normally requires logging) before you add your own handlers to the system. I think that EclipseLink overrides the root logger settings and maybe destroys your configuration.
在将自己的处理程序添加到系统之前,请确保初始化 EclipseLink 日志记录工具(通过执行一些通常需要日志记录的操作)。我认为 EclipseLink 会覆盖根记录器设置,并且可能会破坏您的配置。
回答by maGo
If you are using EclipseLink with JBoss AS7 i recommend Step 5: Configure EclipseLink logging (optional)in the following page on how to get logging correct:
如果您将 EclipseLink 与 JBoss AS7 一起使用,我建议在以下页面中使用步骤 5:配置 EclipseLink 日志记录(可选),了解如何正确获取日志记录:
https://community.jboss.org/wiki/HowToUseEclipseLinkWithAS7
https://community.jboss.org/wiki/HowToUseEclipseLinkWithAS7
In short you will need to:
简而言之,您将需要:
- Add JBossLogger.javafile to you project (attached to the article)
- Add dependency to library jboss-logging
- Set property eclipselink.logging.loggerin persistence.xml
- 将JBossLogger.java文件添加到您的项目中(附在文章中)
- 将依赖添加到库jboss-logging
- 在persistence.xml 中设置属性eclipselink.logging.logger