Configuring JPA logging
Logging supports viewing, tracing, and troubleshooting the runtime behavior of an application. Each of the JPA features provides different levels of logging for you to specify how detailed you want the logging to be.
About this task
jpa-2.0
or jpa-2.1
features, you
can configure logging to aid in troubleshooting. Become familiar with the logging capabilities of
these two features.jpa-2.0
-
There are many supported
jpa-2.0
trace specifications that can be configured through the Liberty configuration. These trace strings can be used in conjunction with any other trace specifications.- Container-managed JPA applications
-
- JPA=all
Enables all JPA container trace and all OpenJPA tracing
- openjpa=all
Enables all OpenJPA tracing
- OpenJPA specific log
channels
openjpa.jdbc.SQL=all
<server> ... <logging traceSpecification="openjpa.jdbc.SQL=all" traceFileName="trace.log" maxFileSize="20" maxFiles="10" traceFormat="BASIC" /> </server>
- JPA=all
- Application managed JPA applications
- When running a JPA application that is application managed, logging and tracing is controlled by
the OpenJPA runtime. All JPA tracing and logging must be configured through OpenJPA persistence properties.
<persistence version="2.0"> <persistence-unit> <properties> <property name="openjpa.Log" value="openjpa.jdbc.SQL=trace"/> </properties> </persistence-unit> </persistence>
- Notable OpenJPA logging persistence properties
openjpa.ConnectionFactoryProperties=PrintParameters=true
-- Iftrue
, SQL bind parameters are included in exceptions and logs.
jpa-2.1
-
When the
jpa-2.1
feature is enabled, all JPA logging and tracing is routed through the Liberty loggers.- Supported trace strings
-
- JPA=all
Enables JPA container trace and all EclipseLink categories
- eclipselink=all
Enables all EclipseLink trace
- EclipseLink specific log categories
- sql, transaction, event, connection, query, cache, propagation, sequencing, ejb, dms, metadata, weaver, properties, server
- ie: eclipselink.sql=All -- Enables EclipseLink SQL trace
<server> ... <logging traceSpecification="eclipselink.sql=all" traceFileName="trace.log" maxFileSize="20" maxFiles="10" traceFormat="BASIC" /> </server>
- JPA=all
- Notable EclipseLink logging persistence properties
eclipselink.logging.parameters
-- Iftrue
, SQL bind parameters are included in exceptions and logs.
Procedure
In the persistence unit definition in the persistence.xml file, specify
the logging level depending on the desired level of logging details that you want.
Specify the
eclipselink.logging.level
property where the value is the logging
level. For the list of logging levels available, refer to the EclipseLink logging wiki page. The
following example will turn on all logging that is available.
<persistence-unit name="pu">
<properties>
<property name="eclipselink.logging.level" value="ALL"/>
...
</properties>
</persistence-unit>