Search code examples
websphereslf4jopenjpa

OpenJPA logging with slf4j on WebSphere


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"/>

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?

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?


Solution

  • I solved it.

    There are four things to do:

    1. Say that OpenJpa logs the statements. That is done by the property entry in the persistence.xml.
    2. 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.
    3. 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
    4. Ask the WebSphere TraceService to hand down the logs from OpenJPA to the application. This is a setting in the WebSphere Administration Console