bea.com | products | dev2dev | support | askBEA

Download Docs | Site Map | Glossary
Search

Internationalization Guide

Loggable Object Reference for BEA WebLogic Server

The following sections provide reference information for Loggable objects:

- About Loggable Objects

- How Loggable Objects Are Used

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 Loggable Objects Are Used

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

For example, consider the test.xml catalog shown in Listing C-1.

Listing C-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/wls600/msgcat.dtd">
>     <message_catalog
>        subsystem="Examples"
>        version="1.0"
>        baseid="500000"
>        endid="500001"
>        loggables="true"
>        >
>        <logmessage
>           messageid="500000"
>           severity="error"
>           method="logIOError(Throwable t)"
>           >
>           <messagebody>
>              IO failure detected.
>           </messagebody>
>           <messagedetail>
>           </messagedetail>
>           <cause>
>           </cause>
>           <action>
>           </action>
>        </logmessage>
>     </message_catalog>

When you run this catalog through the 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 class can be used as shown in Listing C-2.

Listing C-2 Example of Use of Loggable Class

>     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
>     }