问题描述
我的Java EE 6应用程序使用带回送功能的slf4j作为记录框架.现在,我想将OpenJpa的SQL跟踪添加到我的日志文件中. OpenJpa文档说,我可以为此使用参数:
My Java EE 6 application uses slf4j with logback as logging framework.Now I want to add the SQL traces of OpenJpa to my log files. The OpenJpa-Documentation says, I can use a parameter to this:
<property name="openjpa.Log" value="slf4j"/>
我将WebSphere Application Server v8.0.0.1用作Java EE容器.如果我将应用程序部署到服务器,则此参数不会更改任何内容.我可以在WebSphere Admin Console中更改日志级别,这可以正常工作.但是a不能绕过OpenJpa登录到我的slf4j框架.
I use the WebSphere Application Server v8.0.0.1 as Java EE container. If I deploy my application to the server, this parameter does not change anything. I can change log levels in WebSphere Admin Console and this works fine. But a cannot bypass the OpenJpa logging to my slf4j framework.
有人使用这样的配置并解决了问题吗?
Does anyone uses such configuration and solved the problem?
顺便说一句.我知道,InformationCenter-Article http://publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=%2Fcom.ibm.websphere.nd.doc%2Finfo %2Fae%2Fae%2Ftejb_jpatroubleshoot.html 说,该参数将被忽略,但一切都应该可行,是吧?
Btw. I know, that the InformationCenter-Article http://publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=%2Fcom.ibm.websphere.nd.doc%2Finfo%2Fae%2Fae%2Ftejb_jpatroubleshoot.html says, that the parameter will be ignored, but everything should be possible, eh?
推荐答案
我解决了.
有四件事要做:
- 假设OpenJpa记录语句.这是通过persistence.xml中的属性条目完成的.
- 说Slf4j,它也必须从JUL获取日志.这可以通过安装SLF4J的SLF4JBridgeHandler来完成.我通过在应用程序启动时调用的ServletContextListener安装了桥.
- 配置Logback,使其不记录来自JUL的所有日志,而仅记录所需的日志.这是通过在logBack-test.xml中添加LevelChangePropagator来完成的.
- 询问WebSphere TraceService将日志从OpenJPA传递到应用程序.这是WebSphere管理控制台中的设置
- Say that OpenJpa logs the statements. That is done by the property entry in the persistence.xml.
- Say Slf4j that it has to fetch the logs from JUL too. This can be done by installing the SLF4JBridgeHandler by SLF4J. I installed the bridge via a ServletContextListener which is called at application start.
- Configure Logback that it does not log ALL logs from JUL but only the needed Logs. This is done by adding the LevelChangePropagator in the logBack-test.xml
- Ask the WebSphere TraceService to hand down the logs from OpenJPA to the application. This is a setting in the WebSphere Administration Console
这篇关于在WebSphere上使用slf4j进行OpenJPA日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!