B Loggable Object Reference for WebLogic Server

The following sections provide reference information for loggable objects:

About Loggable Objects

By default, all log message catalogs create Logger classes with methods that are used to log the messages to the WebLogic server log. The Logger classes can optionally include methods that return a loggable object instead of logging the message. Loggable objects are useful when you want to generate the log message but actually log it at a later time. They are also useful if you want to use the message text for other purposes, such as throwing an exception.

How To Use Loggable Objects

To create a Logger class that provides methods to return loggable objects, you must set the loggables attribute in the message catalog.

For example, consider the test.xml catalog shown in Example B-1.

Example B-1 test.xml Message Catalog

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE message_catalog PUBLIC "weblogic-message-catalog-dtd" "http://www.bea.com/servers/wls90/dtd/msgcat.dtd">
      method="logIOError(Throwable t)"
         IO failure detected. 

When you run this catalog through the weblogic.i18ngen utility, a Logger class is created for this catalog with the following two methods:

  • logIOError (throwable) - logs the message

  • logIOErrorLoggable (throwable) - returns a loggable object

The loggable object can be used as shown in Example B-2.

Example B-2 Example of Use of Loggable Object

package test;
import weblogic.logging.Loggable;
import weblogic.i18n.testLogger;
try {
  // some IO
} catch (IOException ioe) {
  Loggable l = testLogger.logIOErrorLoggable(ioe);
  l.log();  // log the error
  throw new Exception(l.getMessage());//throw new exception with
         same text as logged