TopLink JPA: How-To Configure Logging

Version: 5/15/06

Introduction

With TopLink JPA you can turn on logging to do the following:

The logging utility is based on the java.util.logging. This utility provides you with nine levels of logging control over the amount and detail of the log output. Note that, as logging is not part of the JPA specification, the information the log output provides is TopLink JPA-specific.

Log Levels

LevelDescription
OFF
This setting disables the generation of the log output. You may want to set logging to OFF during production to avoid the overhead of logging.
SEVERE
This level enables reporting of failure cases only. Usually, if the failure occurs, the application stops.
WARNING
This level enables logging of issues that have a potential to cause problems. For example, a setting that is picked by the application and not by the user.
INFO
This level enables the standard output. The contents of this output is very limited.
CONFIG
This level enables logging of such configuration details as your database login information and some metadata information. You may want to use the CONFIG log level at deployment time.
FINE
This level enables logging of the first level of the debugging information and SQL. You may want to use this log level during debugging and testing, but not at production.
FINER
This level enables logging of more debugging information than the FINE setting. For example, the transaction information is logged at this level. You may want to use this log level during debugging and testing, but not at production.
FINEST
This level enables logging of more debugging information than the FINER setting, such as a very detailed information about certain features (for example, sequencing). You may want to use this log level during debugging and testing, but not at production.

The logging information accumulates at every sequential log level: each log output includes the information from the output of the previous log level. For example, if you set the log level to INFO, your output will include log messages from INFO, WARNING, and SEVERE levels.

Log Level Configuration

The log level configuration is included in the definition of the persistence unit in the persistence.xml file, as follows:

<property name="toplink.logging.level" value="FINE">


Every log output contains various optional details that you can configure using the following properties:

  • Print Timestamp—you can set it in the persistence.xml file (see the following example) to determine when a log output was printed. The default value for this setting is true:

    <property name="toplink.logging.timestamp" value="true">

  • Print Session—you can set it in the persistence.xml file (see the following example) to determine on which underlying session (if any) the message was sent. This setting is applicable to messages that require a database connection such as SQL, and the transaction information. The default value for this setting is true:

    <property name="toplink.logging.session" value="true">

  • Print Thread—you can set it in the persistence.xml file (see the following example) when you are running multithreaded applications to print the hashcode of the thread, which wrote the message. The default value for this setting is true:

    <property name="toplink.logging.thread" value="true">

  • Print Exceptions—you can set it in the persistence.xml file (see the following example) to enable logging of the exceptions's messages at the time when these exceptions are thrown. The default value for this setting is true:

    <property name="toplink.logging.exceptions" value="true">

Summary

You can configure logging at various levels to facilitate the debugging of your application.

See the TopLink JPA Extensions for the complete description of the available extensions.


 
 

 

Left Curve
Popular Downloads
Right Curve
Untitled Document