Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

EclipseLink/Examples/JPA/Logging

< EclipseLink‎ | Examples‎ | JPA
Revision as of 11:33, 22 January 2010 by Adrian.goerler.sap.com (Talk | contribs) (Log Level Configuration)


How To Configure Logging

This document describes how to configuring logging with EclipseLink JPA. See Logging in the EclipseLink User's Guide for complete information.


Introduction

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

  • monitor configuration details
  • facilitate debugging
  • view the SQL that is being sent to the database

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 EclipseLink JPA-specific.


Log Levels

Level Description
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. It is the default logging level if a logging level is not set.
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.
ALL This level currently logs at the same level as FINEST.


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="eclipselink.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="eclipselink.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="eclipselink.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="eclipselink.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="eclipselink.logging.exceptions" value="true"/>

Summary

You can configure logging at various levels to facilitate the debugging of your application. See the Using EclipseLink JPA Extensions for Logging for the complete description of the available extensions.

See also Configuring a custom logger

Back to the top