From Eclipsepedia

Jump to: navigation, search


How to Configure a Custom Logger

This example will detail the minimum steps required to implement a custom logger for EclipseLink JPA.

  • 1) Add the logger to the session via a SessionCustomizer
  • 2) Set the level
  • 3) Override log(SessionLogEntry sessionLogEntry)

This example does not use a logging framework like Apache commons or Log4J yet so that I could isolate EclipseLink behavior.

In your JPA application, add the following changes and the custom logger will get picked at the end of the deploy() after predeploy().

Before the switchover to your custom logger you will encounter 6 instantiations of the DefaultSessionLog implementation of the SessionLog interface.

There is no need to override the other log() functions as they all eventually call log(SessionLogEntry).

Custom Logger Implementation

public class CustomAbstractSessionLog extends AbstractSessionLog implements SessionLog {
    /* @see org.eclipse.persistence.logging.AbstractSessionLog#log(org.eclipse.persistence.logging.SessionLogEntry)
    public void log(SessionLogEntry sessionLogEntry) {
        System.out.println("CUSTOM: " + sessionLogEntry.getMessage()); // untranslated/undecoded message_id

SessionCustomizer Implementation

This is the customizer that will set your custom logger on the session

public class JPAEclipseLinkSessionCustomizer implements SessionCustomizer {
  public void customize(Session aSession) throws Exception {
  // create a custom logger
  SessionLog aCustomLogger = new CustomAbstractSessionLog();
  aCustomLogger.setLevel(1); // finest

Reference SessionCustomizer in persistence.xml

This is the property that you want to add to persistence.xml to pick up the sessionCustomizer.

Invalid language.

You need to specify a language like this: <source lang="html4strict">...</source>

Supported languages for syntax highlighting:

4cs, 6502acme, 6502kickass, 6502tasm, 68000devpac, abap, actionscript, actionscript3, ada, algol68, apache, applescript, apt_sources, arm, asm, asp, asymptote, autoconf, autohotkey, autoit, avisynth, awk, bascomavr, bash, basic4gl, bf, bibtex, blitzbasic, bnf, boo, c, c_loadrunner, c_mac, caddcl, cadlisp, cfdg, cfm, chaiscript, cil, clojure, cmake, cobol, coffeescript, cpp, cpp-qt, csharp, css, cuesheet, d, dcl, dcpu16, dcs, delphi, diff, div, dos, dot, e, ecmascript, eiffel, email, epc, erlang, euphoria, f1, falcon, fo, fortran, freebasic, freeswitch, fsharp, gambas, gdb, genero, genie, gettext, glsl, gml, gnuplot, go, groovy, gwbasic, haskell, haxe, hicest, hq9plus, html4strict, html5, icon, idl, ini, inno, intercal, io, j, java, java5, javascript, jquery, kixtart, klonec, klonecpp, latex, lb, ldif, lisp, llvm, locobasic, logtalk, lolcode, lotusformulas, lotusscript, lscript, lsl2, lua, m68k, magiksf, make, mapbasic, matlab, mirc, mmix, modula2, modula3, mpasm, mxml, mysql, nagios, netrexx, newlisp, nsis, oberon2, objc, objeck, ocaml, ocaml-brief, octave, oobas, oorexx, oracle11, oracle8, otj, oxygene, oz, parasail, parigp, pascal, pcre, per, perl, perl6, pf, php, php-brief, pic16, pike, pixelbender, pli, plsql, postgresql, povray, powerbuilder, powershell, proftpd, progress, prolog, properties, providex, purebasic, pycon, pys60, python, q, qbasic, rails, rebol, reg, rexx, robots, rpmspec, rsplus, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, spark, sparql, sql, stonescript, systemverilog, tcl, teraterm, text, thinbasic, tsql, typoscript, unicon, upc, urbi, uscript, vala, vb, vbnet, vedit, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xbasic, xml, xorg_conf, xpp, yaml, z80, zxbasic

  <property name="eclipselink.session.customizer" value="org.eclipse.persistence.example.unified.integration.JPAEclipseLinkSessionCustomizer"/>


[EL Finest]: 2008.09.12 13:59:36.330--ServerSession(6386542)--Thread(Thread[main,5,main])--property=eclipselink.jdbc.url; value=jdbc:oracle:thin:@ [EL Finest]: 2008.09.12 13:59:36.330--ServerSession(6386542)--Thread(Thread[main,5,main])--property=eclipselink.session.customizer; value=org.eclipse.persistence.example.unified.integration.JPAEclipseLinkSessionCustomizer

>>>Logger switchover<<<

CUSTOM: topLink_version CUSTOM: login_successful ... CUSTOM: INSERT INTO STAT_CLASS (ID, JDK_VERSION, MODIFIED, INTERNAL, LINES, TEST, CLASS_TYPE_CODE, NAME, VERSION, CLASS_TYPE, LABEL, CLASS_PACKAGE) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) bind => [8627, null, 2008-07-04, null, 159, 0, null, XMLPlatformException, concrete, null, 1626, 1366] CUSTOM: execute_query CUSTOM: execute_query CUSTOM: execute_query CUSTOM: INSERT INTO STAT_CLASS (ID, JDK_VERSION, MODIFIED, INTERNAL, LINES, TEST, CLASS_TYPE_CODE, NAME, VERSION, CLASS_TYPE, LABEL, CLASS_PACKAGE) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) bind => [7573, null, 2008-07-04, null, 117, 0, null, QueueableWeakCacheKey, concrete, null, 1626, 1242] CUSTOM: execute_query CUSTOM: execute_query .... CUSTOM: commit_transaction CUSTOM: end_unit_of_work_commit CUSTOM: resume_unit_of_work CUSTOM: release_unit_of_work CUSTOM: client_released CUSTOM: undeploy_begin CUSTOM: sequencing_disconnected CUSTOM: disconnect CUSTOM: initialize_identitymaps CUSTOM: logout_successful CUSTOM: disconnect CUSTOM: disconnect CUSTOM: undeploy_end

Originated: Michael O'Brien against EclipseLink 1.0 build 20080910