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

Difference between revisions of "EclipseLink/Examples/Foundation/Logging"

(Using Log4J)
(Using Log4J)
Line 26: Line 26:
 
== Using Log4J ==
 
== Using Log4J ==
  
UNDER CONSTRUCTION
+
An eclipselink bug report exists for that point : https://bugs.eclipse.org/bugs/show_bug.cgi?id=232240
  
The Oracle TopLink forum has an example provided [http://forums.oracle.com/forums/thread.jspa?messageID=478140&#478140]. An EclipseLink version is still required.
+
It deals about apache commons Logging 1.1 & Log4J integration with eclipseLink 1.0 (so 1.1 should be supported too).
 +
 
 +
How to use Log4J :
 +
 
 +
- add apache commons logging 1.1 & log4J libraries in your classpath
 +
 
 +
- add the sample log4.xml in your classpath : https://bugs.eclipse.org/bugs/attachment.cgi?id=103596
 +
 
 +
- add the following class in the org.eclipse.persistence.logging package of your own project : https://bugs.eclipse.org/bugs/attachment.cgi?id=104821
 +
 
 +
- add the following lines to your persistence.xml :
 +
 
 +
<!-- custom SessionLog implementation to use apache commons logging 1.1
 +
API (so log4J) -->
 +
<property name="eclipselink.logging.logger"
 +
value="org.eclipse.persistence.logging.CommonsLoggingSessionLog"/>
 +
 
 +
 
 +
- Compile & deploy your code : that's done.
 +
 
 +
 
 +
 
 +
'''About log4J levels & eclipselink log levels :'''
 +
 
 +
Of course, you should check that the log4J level for the
 +
org.eclipse.persistence logger (and your root logger and appenders) is
 +
compatible with the eclipselink.logging.level.
 +
 
 +
For example, in log4j.xml :
 +
 
 +
  <logger name="org.eclipse.persistence">
 +
    <level value="info"/>
 +
  </logger>
 +
 
 +
In persistence.xml :
 +
 
 +
<!--
 +
# -----------------------------------------------------------------------------
 +
# Logging level :
 +
#        OFF \u2013 disables logging
 +
#        SEVERE \u2013 logs exceptions indicating EclipseLink cannot continue, as well as any exceptions generated during login. This includes a stack trace.
 +
#        WARNING \u2013 logs exceptions that do not force EclipseLink to stop, including all exceptions not logged with severe level. This does not include a stack trace.
 +
#        INFO \u2013 logs the login/logout per sever session, including the user name. After acquiring the session, detailed information is logged.
 +
#        CONFIG \u2013 logs only login, JDBC connection, and database information.
 +
#        FINE \u2013 logs SQL.
 +
#        FINER \u2013 similar to warning. Includes stack trace.
 +
#        FINEST \u2013 includes additional low level information.
 +
#
 +
# -----------------------------------------------------------------------------
 +
-->
 +
 
 +
eclipselink.logging.level = SEVERE
 +
 
 +
 
 +
'''Change Log levels at runtime :'''
 +
As you may not know, log4J levels can be changed at runtime for debug purposes :
 +
  see the CommonsLoggingSessionLog#setLevel() method :
 +
 
 +
  /**
 +
  * PUBLIC:<p>Set the lw lev to a logger with name space extracted from the given category.</p>
 +
  *
 +
  * @param level
 +
  * @param category
 +
  */
 +
  @Override
 +
  public void setLevel(final int level, final String category)
  
 
== Using Apache Commons Logging ==
 
== Using Apache Commons Logging ==
  
 
UNDER CONSTRUCTION
 
UNDER CONSTRUCTION

Revision as of 06:28, 25 April 2009

How do I integrate with a third party logging framework

EclipseLink's default logging is based on Java (1.4 an higher) java.util.logging but is also extensible to allow other logging frameworks to be used.

This how-to example will illustrate how other logging solutions such as Log4J and Apache common logging can be easily used with EclipseLink.

References

How to configure a custom logger in JPA

Logging Extension Basics

Customizing EclipseLink to use another logging framework or integrate with an existing logging infrastructure involves:

  1. Implementing your own SessionLog
  2. Configuring the use of your SessionLog

Using Log4J

An eclipselink bug report exists for that point : https://bugs.eclipse.org/bugs/show_bug.cgi?id=232240

It deals about apache commons Logging 1.1 & Log4J integration with eclipseLink 1.0 (so 1.1 should be supported too).

How to use Log4J :

- add apache commons logging 1.1 & log4J libraries in your classpath

- add the sample log4.xml in your classpath : https://bugs.eclipse.org/bugs/attachment.cgi?id=103596

- add the following class in the org.eclipse.persistence.logging package of your own project : https://bugs.eclipse.org/bugs/attachment.cgi?id=104821

- add the following lines to your persistence.xml :

<property name="eclipselink.logging.logger" value="org.eclipse.persistence.logging.CommonsLoggingSessionLog"/>


- Compile & deploy your code : that's done.


About log4J levels & eclipselink log levels :

Of course, you should check that the log4J level for the org.eclipse.persistence logger (and your root logger and appenders) is compatible with the eclipselink.logging.level.

For example, in log4j.xml :

 <logger name="org.eclipse.persistence">
   <level value="info"/>
 </logger>

In persistence.xml :


eclipselink.logging.level = SEVERE


Change Log levels at runtime : As you may not know, log4J levels can be changed at runtime for debug purposes :

 see the CommonsLoggingSessionLog#setLevel() method :
 /**
* PUBLIC:

Set the lw lev to a logger with name space extracted from the given category.

  *
  * @param level
  * @param category
  */
 @Override
 public void setLevel(final int level, final String category)

Using Apache Commons Logging

UNDER CONSTRUCTION

Back to the top