+

Search Tips   |   Advanced Search

Logging with the Java Persistence API (JPA) and the application server


Logging allows you to view, trace, and troubleshoot the runtime behavior of an application. JPA provides a flexible logging system that is integrated with the appserver to assist you in troubleshooting problems. Logging channels

Logging can have a negative impact on performance. Limit or disable logging when you run any performance tests.

In additional to the channels used by OpenJPA, a trace group named openjpa enables channels that are prefixed with “openjpa.” Specifying “openjpa” for a trace group will override any other trace group specification that is specific to a channel. Example

openjpa.Runtime=debug:openjpa.jdbc.SQL=all

    openjpa=all

Avoid trouble: The openjpa.Log property will be ignored if it is defined in a container-managed persistence unit that uses the persistence providers that are provided with the appserver. In this case, use the standard trace spec for the appserver. OpenJPA and JPA for WAS implement logging channels to which message data, trace data, and debugging data can be recorded to a configurable repository. The JPA component creates the logging channel at run time and assigns a channel name for identification. The component writes information to the configured repository through the channel. OpenJPA and JPA for WAS create the following channels:

Logging levels Each of the logging channels use logging levels to control which messages are recorded.

The following logging levels are supported by the JPA architecture:

By using a particular logging channel together with logging levels, we can control the types of logging messages and the amount of logging messages that are recorded.

Supported configurations: These logging functions only apply to OpenJPA and JPA for the appserver. Logging functions that are provided in implementations of a third-party persistence provider are not covered. However, if the logging output from a third-party persistence provider is directed to the Java System.out or System.err output streams, the messages are handled by the environment accordingly at run time.

Logging in the appserver

The default JPA persistence provider that is supported by the appserver records messages and tracing data that are automatically integrated into the RAS component. Alternatively, OpenJPA implements a custom logger to route messages from OpenJPA channels to the channels of the appserver. The channel names that are supported by OpenJPA are used as the trace group names in the trace level for the application server. The mappings of OpenJPA logging levels to trace levels in the application server are:


Table 1. Mapping OpenJPA logging levels to appserver trace levels

OpenJPA logging level Trace level for the appserver
TRACE debug
INFO info
WARN warning
ERROR error
FATAL fatal

Logging in a client container and standalone Java application OpenJPA logging uses the basic logging framework and output format:

millis [persistence-unit name]level[thread identifier] channel - message
.

When using pureQuery, the PDQ store manager also uses JDBC in some situations, such as for large result set processing. When tracing all calls to the database, you will need to trace both JDBC and PDQ.

Example:

property name=”wsjpa.Log” value=”SQL=TRACE”/

This will trace the SQL and input parameter values.

property name=”wsjpa.Log” value=”pdq=TRACE, JDBC=TRACE”/
This will perform a detailed trace of calls to the pureQuery runtime as well as any calls to JDBC. If using pureQuery and need to trace calls to the database, you will need to perform both traces. The default logging system accepts the following parameters:

 

  1. Open the persistence.xml file for the application that you want to modify.

  2. Add a property name tag to the XML schema named openjpa.log.

    For example:

    <property name="openjpa.log" .../>
    

  3. Add additional parameters. For example:

    <property name="openjpa.log" value="DefaultLevel=WARN .../>
    

    Supported configurations: To reduce overhead by disabling logging, set the openjpa.log property to NONE and proceed to Step 5.

  4. Designate the logging channels and the logging level. For example:

    <property name="openjpa.log" value="DefaultLevel=WARN, Runtime=INFO, Tool=INFO" .../>
    

  5. Save changes to the file.

 

Results

The next time the application is started the JPA component will log all channels at the WARN logging level and the Runtime and Tool channels at the INFO level.

 

Next steps

OpenJPA allows users to substitute other logging methods. Consult the logging section of the Apache OpenJPA User's Guide for more information and examples.


Enable Enhanced Tracing for Java Persistence API (JPA)
Enable Enhanced Tracing for Java Persistence API (JPA) in a Java SE environment

 

Related tasks


Task overview: Storing and retrieving persistent data with the Java Persistence API (JPA)