PK
`%Doa, mimetypeapplication/epub+zipPK `%D iTunesMetadata.plistv
This appendix describes loggable objects, which are used for generating log messages that are logged at a later time.
This appendix includes the following sections:
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.
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"> <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 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 }
This appendix describes TextFormatter
classes, which provide methods for generating localized versions of message text at run time.
This appendix includes the following sections:
TextFormatter
classes are generated by weblogic.i18ngen
from simple message catalogs. These classes provide methods for generating localized versions of message text at run time.
The following is an example of a Hello_World
application, its simple message catalog, and the TextFormatter
class generated for the catalog.
Example C-1 Example of a Simple 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"> <message_catalog l10n_package="examples.i18n.simple" subsystem="I18N" version="1.0" > <message messageid="HELLO_WORLD" datelastchanged="967575717875" method="helloWorld()" > <messagebody> Hello World! </messagebody> </message> <!-- --> <message messageid="HELLO_AGAIN" datelastchanged="967575717804" method="helloAgain()" > <messagebody> Hello again </messagebody> </message> <!-- --> <message messageid="NTH_HELLO" datelastchanged="967575770971" method="nthHello(int count)" > <messagebody> This is hello number {0,number}. </messagebody> </message> <!-- --> <message messageid="VERSION" datelastchanged="967578656214" method="version(String version)" > <messagebody> Catalog version: {0} </messagebody> </message> <!-- --> <message messageid="I18N_PACKAGE" datelastchanged="967578691394" method="i18nPackage(String pkg)" > <messagebody> I18n Package: {0} </messagebody> </message> <!-- --> <message messageid="L10N_PACKAGE" datelastchanged="967578720156" method="l10nPackage(String pkg)" > <messagebody> L10n Package: {0} </messagebody> </message> <!-- --> <message messageid="SUBSYSTEM" datelastchanged="967578755587" method="subSystem(String sub)" > <messagebody> Catalog subsystem: {0} </messagebody> </message> </message_catalog>
The following is an example of an application using the HelloWorld catalog. The example shows various ways of internationalizing an application using simple message catalogs.
Example C-2 Example of an Application Using the HelloWorld Catalog
package examples.i18n.simple; import java.util.Locale; import java.text.MessageFormat; import weblogic.i18n.Localizer; import weblogic.i18ntools.L10nLookup; /** * This example shows various ways of internationalizing an application * using simple message catalogs. * <p> * Usage: java examples.i18n.simple.HelloWorld [lang [country]] * <p> * lang is a 2 character ISO language code. e.g. "en" * country is a 2 character ISO country code. e.g. "US" * <p> * Usage of any of the languages supported by this example presumes * the existence of the appropriate OS localization software and character * encodings. * <p> * The example comes with catalogs for English (the default) and French. * The catalog source is in the following files, and were built * using the catalog editing utility, weblogic.i18ntools.gui.MessageEditor. * <p> * <pre> * English(base language) ../msgcat/Helloworld.xml * French ../msgcat/fr/FR/HelloWorld.xml * </pre> * <p> * To build this example run the bld.sh(UNIX) or bld.cmd (NT) scripts from * the examples/i18n/simple directory. CLIENT_CLASSES must be set up and * needs to be in the classpath when running the example. */ public final class HelloWorld { public static void main(String[] argv) { /* * The easiest method for displaying localized text is to * instantiate the generated formatter class for the HelloWorld catalog. * This class contains convenience methods that return localized text for * each message defined in the catalog. The class name is * the catalog name followed by "TextFormatter". * * Typically, you would use the default constructor to obtain * formatting in the current locale. This example uses a locale * based on arguments to construct the TextFormatter. */ Locale lcl; if (argv.length == 0) { // default is default locale for JVM lcl = Locale.getDefault(); } else { String lang = null; String country = null; //get the language code lang = argv[0]; if (argv.length >= 2) { // get the country code country = argv[1]; } lcl = new Locale(lang,country); } /* * Get formatter in appropriate locale. */ HelloWorldTextFormatter fmt = new HelloWorldTextFormatter(lcl); fmt.setExtendedFormat(true); /* * Print the text in the current locale. */ System.out.println(fmt.helloWorld()); /* * Alternatively, text can be accessed and formatted manually. In this * case you must obtain the Localizer class for the catalog. The * Localizer class is formed from the l10n_package attribute in the * catalog, the catalog name, and the string "TextLocalizer". */ Localizer l10n = L10nLookup.getLocalizer (lcl,"examples.i18n.simple.HelloWorldTextLocalizer"); System.out.println(l10n.get("HELLO_AGAIN")); /* * If the message accepts arguments, they can be passed to the * method defined for the message. */ System.out.println(fmt.nthHello(3)); /* * If using the manual method, you must manually apply the argument to * the text using the MessageFormat class. */ String text = l10n.get("NTH_HELLO"); Object[] args = {new Integer(4)}; System.out.println(MessageFormat.format(text,args)); /* * The Localizer class also provides methods for accessing catalog * information. */ System.out.println(fmt.version(l10n.getVersion())); System.out.println(fmt.l10nPackage(l10n.getL10nPackage())); System.out.println(fmt.i18nPackage(l10n.getI18nPackage())); System.out.println(fmt.subSystem(l10n.getSubSystem())); } }
The following listing shows an example of the generated TextFormatter
for the HelloWorld catalog.
Example C-3 Example of Generated TextFormatter Class for the HelloWorld Catalog
package examples.i18n.simple;import java.text.MessageFormat; import java.text.DateFormat; import java.util.Date; import java.util.Locale; import weblogic.i18n.Localizer; import weblogic.i18ntools.L10nLookup; public class HelloWorldTextFormatter { private Localizer l10n; private boolean format=false; // constructors public HelloWorldTextFormatter() { l10n = L10nLookup.getLocalizer(Locale.getDefault(), "examples.i18n.simple.HelloWorldTextLocalizer"); } public HelloWorldTextFormatter(Locale l) { l10n = L10nLookup.getLocalizer(l,"examples.i18n.simple.HelloWorldTextLocalizer"); } public static HelloWorldTextFormatter getInstance() { return new HelloWorldTextFormatter(); } public static HelloWorldTextFormatter getInstance(Locale l) { return new HelloWorldTextFormatter(l); } public void setExtendedFormat(boolean fmt) { format = fmt; } public boolean getExtendedFormat() { return format; /** * Hello World! */ public String helloWorld() { String fmt = ""; String id = "HELLO_WORLD" ; String subsystem = "I18N" ; Object [] args = { }; String output = MessageFormat.format(l10n.get(id) , args); if (getExtendedFormat()) { DateFormat dformat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG); fmt = "<"+dformat.format(new Date())+"><"+subsystem+"><"+id+"> "; } return fmt+output; } /** * Hello again */ public String helloAgain() { String fmt = ""; String id = "HELLO_AGAIN" ; String subsystem = "I18N" ; Object [] args = { }; String output = MessageFormat.format(l10n.get(id) , args); if (getExtendedFormat()) { DateFormat dformat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG); fmt = "<"+dformat.format(new Date())+"><"+subsystem+"><"+id+">"; } return fmt+output; } /** * This is hello number {0,number}. */ public String nthHello(int arg0) { String fmt = ""; String id = "NTH_HELLO" ; String subsystem = "I18N" ; Object [] args = { new Integer(arg0) }; String output = MessageFormat.format(l10n.get(id) , args); if (getExtendedFormat()) { DateFormat dformat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG); fmt = "<"+dformat.format(new Date())+"><"+subsystem+"><"+id+">"; } return fmt+output; } /** * Catalog version: {0} */ public String version(String arg0) { String fmt = ""; String id = "VERSION" ; String subsystem = "I18N" ; Object [] args = { arg0 }; String output = MessageFormat.format(l10n.get(id) , args); if (getExtendedFormat()) { DateFormat dformat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG); fmt = "<"+dformat.format(new Date())+"><"+subsystem+"><"+id+">"; } return fmt+output; } /** * I18n Package: {0} */ public String i18nPackage(String arg0) { String fmt = ""; String id = "I18N_PACKAGE" ; String subsystem = "I18N" ; Object [] args = { arg0 }; String output = MessageFormat.format(l10n.get(id) , args); if (getExtendedFormat()) { DateFormat dformat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG); fmt = "<"+dformat.format(new Date())+"><"+subsystem+"><"+id+">"; } return fmt+output; } /** * L10n Package: {0} */ public String l10nPackage(String arg0) { String fmt = ""; String id = "L10N_PACKAGE" ; String subsystem = "I18N" ; Object [] args = { arg0 }; String output = MessageFormat.format(l10n.get(id) , args); if (getExtendedFormat()) { DateFormat dformat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG); fmt = "<"+dformat.format(new Date())+"><"+subsystem+"><"+id+">"; } return fmt+output; } /** * Catalog subsystem: {0} */ public String subSystem(String arg0) { String fmt = ""; String id = "SUBSYSTEM" ; String subsystem = "I18N" ; Object [] args = { arg0 }; String output = MessageFormat.format(l10n.get(id) , args); if (getExtendedFormat()) { DateFormat dformat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG); fmt = "<"+dformat.format(new Date())+"><"+subsystem+"><"+id+">"; } return fmt+output; } }
This chapter describes the processes required for internationalization and localization.
This chapter includes the following sections:
Oracle has adopted the World Wide Web Consortium's (W3C) recommendations for standard formats and protocols that are usable worldwide in all languages and in all writing systems. These standards are part of the Java internationalization APIs that are used by WebLogic Server. Internationalization (I18N) refers to the process of designing software so that it can be adapted to various languages and regions easily, cost-effectively, and, in particular, without engineering changes to the software. Localization (L10N) is the use of locale-specific language and constructs at run time.
Localization covers not only language, but collation, date and time formats, monetary formats, and character encoding. Messages that are logged to the WebLogic server log can be localized to meet your particular requirements.
WebLogic Server internationalization supports localization of two types of data:
Log messages - Log messages are informational messages that are written to the server log, and may also contain error messages if the appropriate message arguments are included in the message definition. See Elements of a Log Message Catalog.
Simple text - Simple text is any text other than log messages and exceptions that the server must display, such as the output from a utility. Examples of simple text include usage messages, graphical user interface (GUI) labels, and error messages. See Elements of a Simple Text Catalog.
All internationalized text is defined in message catalogs, each of which defines a collection of log messages or simple text. Log messages contain data that is written to the log file. This data is predominantly dynamic and contains information that is specific to the current state of the application and system. When merged with text in a localized log message catalog, this data results in well-formatted, localized messages that describe the error condition in the language of the user. The output sent to the WebLogic Server Administration Console is simple text. As with log messages, simple text can be merged with dynamic data.
To create an internationalized message, you externalize all message strings in a message catalog so that the strings can be converted to multiple locales without changing or recompiling the code. The application code supplies run-time values to the logging methods. The logging methods merge the code with the message string in the catalog according to the current locale. The application code then prints a localized message in the log files.
There are three types of message catalogs:
Log message catalogs - Collections of log messages. See Elements of a Log Message Catalog.
Simple text message catalogs - Collections of simple text messages. See Elements of a Simple Text Catalog.
Locale message catalogs - Collections of locale-specific messages corresponding to a top-level log message or simple text catalog. See Elements of a Locale-Specific Catalog.
Message IDs in log message catalogs or locale message catalogs are unique across all log message or locale message catalogs. Within the message catalog file, each localized version of the message is assigned a unique message ID and message text specific to the error. Ideally, a message is logged from only one location within the system so that a support team can easily find it. Message IDs in simple text catalogs are unique within each simple text catalog.
See Chapter 4, "Using Message Catalogs with WebLogic Server," for more detailed information about message catalogs.
To view the WebLogic Server message catalogs, see Oracle WebLogic Server Error Message Reference.
WebLogic Server uses the Java internationalization interfaces to provide internationalization and localization. In addition to understanding how WebLogic Server handles internationalization, you should be familiar with the Java internationalization interfaces and the following classes included in the Java Development Kit (JDK).
Class | Description |
---|---|
java.util.Locale |
Represents a specific geographical, political, or cultural region. |
java.util.ResourceBundle |
Provides containers for locale-specific objects. |
java.text.MessageFormat |
Produces concatenated messages in a language-neutral way. |
The following steps summarize how you create an internationalized message to use with WebLogic Server. Later sections of this guide describe these steps in more detail.
Create or edit a top-level log message catalog or simple text message catalog by defining the messages in the catalog.
In addition to message text, include information about the type and placement of any run-time values that the message contains. For details, see Chapter 6, "Using the WebLogic Server Message Editor."
Run weblogic.i18ngen
to validate the catalog you created or edited in Step 1 and generate run-time classes.
The generated classes contain a method for each message. The class is defined according to information specified in the message catalog entry. The classes include methods for logging or getting message text, depending on the type of catalog. The class name ends with Logger
or TextFormatter
. For details, see weblogic.i18ngen Utility.
Create locale-specific catalogs as required for the message catalog you created in Step 1. See Example Locale-Specific Catalog.
Run weblogic.l10ngen
to process the locale-specific catalogs. For details, see weblogic.l10ngen Utility.
Configure your application to use the Logger
or TextFormatter
classes you generated in Step 2. When the application logs or returns a message, the message is written using the localized version of the text according to the Logger
or TextFormatter
classes used.
For more detailed information, see Chapter 5, "Writing Messages to the WebLogic Server Log."
Adding WebLogic Logging Services to Applications Deployed on Oracle WebLogic Server
12c (12.1.2)
E28148-02
May 2014
Documentation for developers that describes how to use WebLogic Server logging services to monitor application events. It describes WebLogic support for internationalization and localization of log messages, and shows you how to use the templates and tools provided with WebLogic Server to create or edit message catalogs that are locale-specific.
Oracle Fusion Middleware Adding WebLogic Logging Services to Applications Deployed on Oracle WebLogic Server, 12c (12.1.2)
E28148-02
Copyright © 2007, 2014, Oracle and/or its affiliates. All rights reserved.
This software and related documentation are provided under a license agreement containing restrictions on use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is prohibited.
The information contained herein is subject to change without notice and is not warranted to be error-free. If you find any errors, please report them to us in writing.
If this is software or related documentation that is delivered to the U.S. Government or anyone licensing it on behalf of the U.S. Government, the following notice is applicable:
U.S. GOVERNMENT END USERS: Oracle programs, including any operating system, integrated software, any programs installed on the hardware, and/or documentation, delivered to U.S. Government end users are "commercial computer software" pursuant to the applicable Federal Acquisition Regulation and agency-specific supplemental regulations. As such, use, duplication, disclosure, modification, and adaptation of the programs, including any operating system, integrated software, any programs installed on the hardware, and/or documentation, shall be subject to license terms and license restrictions applicable to the programs. No other rights are granted to the U.S. Government.
This software or hardware is developed for general use in a variety of information management applications. It is not developed or intended for use in any inherently dangerous applications, including applications that may create a risk of personal injury. If you use this software or hardware in dangerous applications, then you shall be responsible to take all appropriate failsafe, backup, redundancy, and other measures to ensure its safe use. Oracle Corporation and its affiliates disclaim any liability for any damages caused by use of this software or hardware in dangerous applications.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
Intel and Intel Xeon are trademarks or registered trademarks of Intel Corporation. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. AMD, Opteron, the AMD logo, and the AMD Opteron logo are trademarks or registered trademarks of Advanced Micro Devices. UNIX is a registered trademark of The Open Group.
This software or hardware and documentation may provide access to or information on content, products, and services from third parties. Oracle Corporation and its affiliates are not responsible for and expressly disclaim all warranties of any kind with respect to third-party content, products, and services. Oracle Corporation and its affiliates will not be responsible for any loss, costs, or damages incurred due to your access to or use of third-party content, products, or services.
This document describes how you use WebLogic Server logging services to monitor application events. It describes WebLogic support for internationalization and localization of log messages, and shows you how to use the templates and tools provided with WebLogic Server to create or edit message catalogs that are locale-specific.
This section describes the contents and organization of this guide—Adding WebLogic Logging Services to Applications Deployed on Oracle WebLogic Server.
This document is a resource for Java Platform, Enterprise Edition (Java EE) application developers who want to use WebLogic message catalogs and logging services as a way for their applications to produce log messages and want to integrate their application logs with WebLogic Server logs. This document is relevant to all phases of a software project, from development through test and production phases.
This document does not address how you configure logging, subscribe to and filter log messages. For links to information on these topics, see Related Documentation.
It is assumed that the reader is familiar with Java EE and Web technologies, object-oriented programming techniques, and the Java programming language.
The document is organized as follows:
Chapter 1, "Introduction and Roadmap," describes the scope of this guide and lists related documentation.
Chapter 2, "Application Logging and WebLogic Logging Services," discusses how to use WebLogic logging services to monitor application events.
Chapter 3, "Internationalization and Localization for WebLogic Server," summarizes the processes required for internationalization and localization.
Chapter 4, "Using Message Catalogs with WebLogic Server," describes message catalog types, message definitions, elements, and arguments.
Chapter 5, "Writing Messages to the WebLogic Server Log," describes how to create and use message catalogs and how to use the NonCatalogLogger
class to write log messages.
Chapter 6, "Using the WebLogic Server Message Editor," explains how to use the Message Editor that is included with WebLogic Server.
Chapter 7, "Using the WebLogic Server Internationalization Utilities," explains how to use the internationalization utilities included with WebLogic Server.
Appendix A, "Localizer Class Reference for WebLogic Server," describes Localizer
classes, Localizer
methods, key values for Localizers
, and lookup properties for Localizers
.
Appendix B, "Loggable Object Reference for WebLogic Server," describes loggable objects
and how they are used.
Appendix C, "TextFormatter Class Reference for WebLogic Server," provides an example of an application that uses a TextFormatter
class.
Appendix D, "Logger Class Reference for WebLogic Server," describes Logger
classes and provides an example of a message catalog and its corresponding Logger
class.
The corporate Web site provides all documentation for WebLogic Server. Specifically, "View and configure logs" in the Oracle WebLogic Server Administration Console Online Help describes configuring log files and log messages that a WebLogic Server instance generates, and Configuring Log Files and Filtering Log Messages for Oracle WebLogic Server describes configuring WebLogic Server to write messages to log files, filtering message output, and listening for the log messages that WebLogic Server broadcasts.
For general information about internationalization and localization, refer to the following sources:
The Java Developer Connection at http://www.oracle.com/technetwork/java/index.html
The Internationalization section of the World Wide Web Consortium (W3C) Web Site at http://www.w3.org
In addition to this document, we provide a variety of logging code samples and tutorials that show logging configuration and API use.
MedRec is an end-to-end sample Java EE application shipped with WebLogic Server that simulates an independent, centralized medical record management system. The MedRec application provides a framework for patients, doctors, and administrators to manage patient data using a variety of different clients.
MedRec demonstrates WebLogic Server and Java EE features, and highlights recommended best practices. MedRec is optionally installed with the WebLogic Server installation. You can start MedRec from the ORACLE_HOME
\user_projects\domains\medrec
directory, where ORACLE_HOME
is the directory you specified as the Oracle Home when you installed Oracle WebLogic Server. For more information, see "Sample Applications and Code Examples" in Understanding Oracle WebLogic Server.
WebLogic Server optionally installs API code examples in EXAMPLES_HOME
\wl_server\examples\src\examples
, where EXAMPLES_HOME
represents the directory in which the WebLogic Server code examples are configured. For more information, see "Sample Applications and Code Examples" in Understanding Oracle WebLogic Server.
This example shows various methods for displaying localized text using simple message catalogs. Using any of the languages supported by the example requires the appropriate operating system localization software and character encoding. The package that contains this example is:
java examples.i18n.simple.HelloWorld [lang [country]]
where lang
is a two-character ISO language code (for example, en for English) and country
is a two-character ISO country code (for example, US for the United States).
The files are located in EXAMPLES_HOME
\wl_server\examples\src\examples\i18n\simple
, where EXAMPLES_HOME
represents the directory in which the WebLogic Server code examples are configured. For more information, see "Sample Applications and Code Examples" in Understanding Oracle WebLogic Server.
For a comprehensive listing of the new WebLogic Server features introduced in this release, see What's New in Oracle WebLogic Server.
This appendix describes Logger
classes, which provide the interface to WebLogic Server logging, and provides an example of a message catalog and its corresponding Logger
class.
This appendix includes the following sections:
The classes generated by i18ngen
are known as Logger
classes. Logger
classes provide the interface to WebLogic Server logging. For catalog Xyz.xml,
a Logger
class XyzLogger
is generated.
The Logger
class provides methods to log all messages defined in a catalog to the WebLogic server log. The methods included are the same as those defined in the associated catalog. If the catalog specifies the loggables
attribute as true, then Loggable
methods are also generated for each message.
For more information, see Appendix B, "Loggable Object Reference for WebLogic Server."
Example D-1 contains an example of a generated logger class.
Example D-1 Example of Generated Logger Class
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE message_catalog PUBLIC "weblogic-message-catalog-dtd" "http://www.bea.com/servers/wls90/dtd/msgcat.dtd"> <message_catalog i18n_package="examples.i18n.logging" l10n_package="examples.i18n.logging" subsystem="I18N" version="1.0" baseid="600000" endid="610000" loggables="true" > <logmessage messageid="600000" method="logEntry()" severity="info" > <messagebody>Starting I18nLog example...</messagebody> <messagedetail></messagedetail> <cause></cause> <action></action> </logmessage> <logmessage messageid="600001" method="testArgs(String name,int cnt)" severity="debug" > <messagebody>Class {0} started with {1,number} arguments.</messagebody> <messagedetail></messagedetail> <cause></cause> <action></action> </logmessage> <logmessage messageid="600002" method="logTrace(Throwable t)" severity="error" stacktrace="true" > <messagebody>This message is followed by a trace</messagebody> <messagedetail></messagedetail> <cause></cause> <action></action> </logmessage> <logmessage messageid="600003" method="logNoTrace(Throwable t)" severity="warning" stacktrace="false" > <messagebody>This message is not followed by a trace, but we can insert its text : {0}</messagebody> <messagedetail></messagedetail> <cause></cause> <action></action> </logmessage> <logmessage messageid="600004" method="getId()" severity="info" > <messagebody>This message's id will be in the next message</messagebody> <messagedetail>A message can contain additional detailed information.</messagedetail> <cause>This message is displayed on purpose</cause> <action>Nothing to do, the example is working</action> </logmessage> <logmessage messageid="600005" method="showId(String id)" severity="info" > <messagebody>The previous message logged had message id {0}</messagebody> <messagedetail></messagedetail> <cause></cause> <action></action> </logmessage> </message_catalog>
Example D-2 shows the corresponding Java source code generated by weblogic.i18ngen
.
Example D-2 Example of Generated Logger Class
package examples.i18n.logging; import weblogic.logging.MessageLogger; import weblogic.logging.Loggable; import java.util.MissingResourceException; public class I18nLogLogger { /** * Starting I18nLog example... * @exclude * * messageid: 600000 * severity: info */ public static String logEntry() { Object [] args = { }; MessageLogger.log( "600000", args, "examples.i18n.logging.I18nLogLogLocalizer"); return "600000"; } public static Loggable logEntryLoggable() throws MissingResourceException { Object[] args = { }; return new Loggable("600000", args); } /** * Class {0} started with {1,number} arguments. * @exclude * * messageid: 600001 * severity: debug */ public static String testArgs(String arg0, int arg1) { Object [] args = { arg0, new Integer(arg1) }; MessageLogger.log( "600001", args, "examples.i18n.logging.I18nLogLogLocalizer"); return "600001"; } public static Loggable testArgsLoggable(String arg0, int arg1) throws MissingResourceException { Object[] args = { arg0, new Integer(arg1) }; return new Loggable("600001", args); } /** * This message is followed by a trace * @exclude * * messageid: 600002 * severity: error */ public static String logTrace(Throwable arg0) { Object [] args = { arg0 }; MessageLogger.log( "600002", args, "examples.i18n.logging.I18nLogLogLocalizer"); return "600002"; } public static Loggable logTraceLoggable(Throwable arg0) throws MissingResourceException { Object[] args = { arg0 }; return new Loggable("600002", args); } /** * This message is not followed by a trace, but we can insert its text : {0} * @exclude * * messageid: 600003 * severity: warning */ public static String logNoTrace(Throwable arg0) { Object [] args = { arg0 }; MessageLogger.log( "600003", args, "examples.i18n.logging.I18nLogLogLocalizer"); return "600003"; } public static Loggable logNoTraceLoggable(Throwable arg0) throws MissingResourceException { Object[] args = { arg0 }; return new Loggable("600003", args); } /** * This message's id will be in the next message * @exclude * * messageid: 600004 * severity: info */ public static String getId() { Object [] args = { }; MessageLogger.log( "600004", args, "examples.i18n.logging.I18nLogLogLocalizer"); return "600004"; } public static Loggable getIdLoggable() throws MissingResourceException { Object[] args = { }; return new Loggable("600004", args); } /** * The previous message logged had message id {0} * @exclude * * messageid: 600005 * severity: info */ public static String showId(String arg0) { Object [] args = { arg0 }; MessageLogger.log( "600005", args, "examples.i18n.logging.I18nLogLogLocalizer"); return "600005"; } public static Loggable showIdLoggable(String arg0) throws MissingResourceException { Object[] args = { arg0 }; return new Loggable("600005", args); } }
Example D-3 shows an example application that uses the weblogic.i18nLog
(internationalized (I18n) logging interfaces). The example logs an informational message.
Example D-3 Example of Application Using i18nLog
package examples.i18n.logging; import java.util.Locale; import weblogic.i18n.Localizer; import weblogic.i18ntools.L10nLookup; import weblogic.logging.Loggable; /** * This example shows how to use the internationalized (I18n) logging interfaces. * <p> * usage: java examples.i18n.logging.I18nLog * <p> * Build procedure: run bld.sh (UNIX) or bld.cmd (NT). These scripts * process the I18nLog.xml catalog, producing the logging class, * <tt>examples.i18n.logging.I18nLogLogger</tt>. This class contains static * methods for logging messages to the WLS server log. The methods * and arguments are defined in the I18nLog.xml catalog. This example also * uses a simple message catalog, I18nSimple.xml. */ public class I18nLog { public I18nLog() {} public static void main(String[] argv) { /** * This call just logs an info message. There are no arguments defined * for this method. * * This also shows how to use the Loggable form of the method. */ Loggable ll = I18nLogLogger.logEntryLoggable(); ll.log(); System.out.println(ll.getMessage()); /** * Here's an example of a message including a variety * of arguments. */ I18nLogLogger.testArgs(I18nLog.class.getName(),argv.length); /** * If a Throwable is passed then it will result in a stack trace * being logged along with the method by default. */ Throwable t = new Throwable("Test with stack trace"); I18nLogLogger.logTrace(t); /** * Messages can optionally be defined to not log a stack trace. */ I18nLogLogger.logNoTrace(t); /** * The logger methods return the message id for applications * that want to do more than just log these messages. */ String messageId = I18nLogLogger.getId(); I18nLogLogger.showId(messageId); /** * The message id can be used to obtain the different attributes * of a message. The L10nLookup object provides access to the catalogs * via Localizer classes. Localizers provide the access to individual * messages. Each log message catalog has two Localizers: one for * general message information and one for the detailed attributes. * * The basic Localizer provides access to catalog information: * Version * L10n Package - package for catalog data * I18n Package - package for Logger methods * Subsystem - catalog subsystem * For each message it also provides: * Severity: debug, info, warning, error * Message Body - the message text * Stack option - whether to log a stack trace * * First get to the L10nLookup properties, then use them to get the * Localizers for the message. */ L10nLookup l10n = L10nLookup.getL10n(); /** * This returns the basic Localizer (arg 3 = false) */ Localizer lcl = l10n.getLocalizer(messageId,Locale.getDefault(),false); /** * This returns the detailed Localizer (arg 3 = true) */ Localizer lclDetail = l10n.getLocalizer(messageId,Locale.getDefault(),true); /** * Use this appplication's simple message catalog to display the * log message catalog information */ I18nSimpleTextFormatter fmt = new I18nSimpleTextFormatter(); System.out.println(fmt.version(messageId,lcl.getVersion())); System.out.println(fmt.l10nPackage(messageId,lcl.getL10nPackage())); System.out.println(fmt.i18nPackage(messageId,lcl.getI18nPackage())); System.out.println(fmt.subsystem(messageId,lcl.getSubSystem())); System.out.println(fmt.severity(messageId,lcl.getSeverity(messageId))); System.out.println(fmt.body(messageId,lcl.getBody(messageId))); System.out.println(fmt.stack(messageId,lcl.getStackTrace(messageId))); /** * Now for the detailed information. */ System.out.println(fmt.detail(messageId,lclDetail.getDetail(messageId))); System.out.println(fmt.cause(messageId,lclDetail.getCause(messageId))); System.out.println(fmt.action(messageId,lclDetail.getAction(messageId))); } }
This preface describes the document accessibility features and conventions used in this guide—Adding WebLogic Logging Services to Applications Deployed on Oracle WebLogic Server.
For information about Oracle's commitment to accessibility, visit the Oracle Accessibility Program website at http://www.oracle.com/pls/topic/lookup?ctx=acc&id=docacc
.
Access to Oracle Support
Oracle customers have access to electronic support through My Oracle Support. For information, visit http://www.oracle.com/pls/topic/lookup?ctx=acc&id=info
or visit http://www.oracle.com/pls/topic/lookup?ctx=acc&id=trs
if you are hearing impaired.
The following text conventions are used in this document:
Convention | Meaning |
---|---|
boldface |
Boldface type indicates graphical user interface elements associated with an action, or terms defined in text or the glossary. |
italic |
Italic type indicates book titles, emphasis, or placeholder variables for which you supply particular values. |
|
Monospace type indicates commands within a paragraph, URLs, code in examples, text that appears on the screen, or text that you enter. |