OpenJPA registration with slf4j on WebSphere

My Java EE 6 application uses slf4j with the logback function as a logging environment. Now I want to add OpenJpa SQL traces to the log files. The OpenJpa documentation says that I can use the parameter:

<property name="openjpa.Log" value="slf4j"/> 

I am using WebSphere Application Server v8.0.0.1 as a Java EE container. If I deploy my application to the server, this option will not change anything. I can change the log levels in the WebSphere administration console, and this works fine. But you cannot get around registering OpenJpa in my slf4j framework.

Does anyone use this configuration and solve the problem?

Btw. I know that 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 the parameter will be ignored, but everything should be possible, eh?

+4
source share
2 answers

I solved it.

There are four things:

  • Suppose OpenJpa registers instructions. This is done by writing the property in the persistence.xml file.
  • Tell Slf4j that it should also extract logs from the JUL. This can be done by installing SLF4JBridgeHandler on SLF4J. I installed the bridge through the ServletContextListener, which is called when the application starts.
  • Configure Logback so that it does not log ALL logs from the JUL, but only the necessary logs. This is done by adding LevelChangePropagator to logBack-test.xml
  • Ask WebSphere TraceService to transfer logs from OpenJPA to the application. This is a setting in the WebSphere administration console
0
source

I do not know which version of OpenJPA is built into WAS 8.0.

In OpenJPA 1.x it was not possible to use "slf4j". The workaround was to copy the org.apache.openjpa.lib.log.SLF4JLogFactory class from OpenJPA 2.x into your application and use 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 just a convenient trick.

OpenJPA 2.x has SLF4JLogFactory , so it should work with your current settings; maybe you installed it in a place that is overridden by a different configuration? For example, if you configure JPA through the EntityManagerFactory propertyMap, it takes precedence over the settings in persistence.xml .

0
source

Source: https://habr.com/ru/post/1388955/


All Articles