Skip to main content

How to configure a logger type in TopLink Essentials (Part 2)

Posted by guruwons on September 22, 2006 at 1:29 AM PDT

Previously I bloged about How to use Java Logger in Java SE mode - a workaround to change logger type. But the workaround is no more needed. GlassFish v2(from b17) implemented a new feature - the configuration for logger type for this.

It's very easy to use Java logger in Java SE mode, just add following property to persistence.xml.

  <property name="toplink.logging.logger" value="JavaLogger"/>

Or you can do it programatically like below.

  Map properties = new HashMap();
  properties.add("toplink.logging.logger", "JavaLogger");
  ...
  EntityManagerFactory emf = Persistence.createEntityManagerFactory("your-unit-name", properties);

Valid values are one of the following or custom class name which implements oracle.toplink.essentials.logging.SessionLog.

 * DefaultLogger - internal default logger(Standard out).
 * JavaLogger - Java logger.

In Java EE environment, this property is normally not required because AppServers such as GlassFish is already using JavaLogger by implciticly adding ServerPlatform("toplink.target-server" or "toplink.server.platform.class.name") property. But if you specify "toplink.logging.logger" property then it will override the ServerPlatform's logger configuration.

Implementing a new logger type or extending existing logger

Currently there are just two logger types.
But you can add a new logger type if you need a different type of logger(such as log4j).

To implement acustom logger make a logger class by implementing oracle.toplink.essentials.logging.SessionLog or extending oracle.toplink.essentials.logging.AbstractSessionLog. And put the class name on the logger type property.

  <property name="toplink.logging.logger" value="your-logger-class-name"/>

See oracle.toplink.essentials.logging.JavaLog source for reference.

If you want a special kind of logger, consider extending existing logger. You may be able to implement a logger which handles SQL log specially - see  SessionLog's SQL category.

Make your own logger and if it is useful for others, please contribute by sending it to persistence@glassfish.dev.java.net !

 

Related Topics >>