5

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?

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Steven Rudolf
  • 275
  • 1
  • 8
  • 17

2 Answers2

0

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
Steven Rudolf
  • 275
  • 1
  • 8
  • 17
0

I don't know what version of OpenJPA is embedded in WAS 8.0.

In OpenJPA 1.x there was no possibility to use "slf4j". A workaround was copying the class org.apache.openjpa.lib.log.SLF4JLogFactory from OpenJPA 2.x sources to your application and using it directly:

<property name="openjpa.Log" value="org.apache.openjpa.lib.log.SLF4JLogFactory"/>

You can always specify the factory class name directly, the short name is only a convenience trick.

In OpenJPA 2.x the SLF4JLogFactory is present, so it should work with your current settings; perhaps you set it in a place that is overridden by other configuration? For example, if you configure JPA through EntityManagerFactory's propertyMap, it takes precedence over the settings in persistence.xml.

MaDa
  • 10,511
  • 9
  • 46
  • 84
  • Thanks a lot for your reply! Unfortunately it seems that the openjpa.Log parameter will be ignored by the Websphere persistence implementation. I am using the default persistence provider (com.ibm.websphere.persistence.PersistenceProviderImpl), so I can use the container provided datasources. – Steven Rudolf Jan 04 '12 at 08:46
  • Built-in OpenJPA can also use container-provided data sources - it would be kind of useless without this, wouldn't it? – MaDa Jan 04 '12 at 09:43