Skip Headers
Oracle® Containers for J2EE Developer's Guide
10g (10.1.3.4.0)

Part Number E12290-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

4 Logging Implementation Guidelines

This chapter discusses the Oracle guidelines for implementing logging functionality in applications that will be deployed to OC4J. It enables applications that use the standard Java logging framework to integrate Java logging with Oracle Diagnostic Logging (ODL) and take advantage of log analysis tools provided by Oracle, as the following topics describe:

For information on logging configuration and usage in OC4J, see the Oracle Containers for J2EE Configuration and Administration Guide.

Overview of the Java and Oracle Logging Frameworks

The Java and Oracle logging frameworks are integrated to enable Java log output to be generated in Oracle format.

The Java Logging Framework

The Java logging framework, introduced in JDK 1.4, provides extensive logging APIs through the java.util.logging package. For an overview of the java.util.logging package, visit http://java.sun.com/j2se/1.4.2/docs/api/overview-summary.html.

For an overview of the Java logging framework, visit Sun's site on the subject at http://java.sun.com/j2se/1.4.2/docs/guide/util/logging/overview.html.

The Oracle Diagnostic Logging Framework

The Oracle Diagnostic Logging framework, or ODL, provides plug-in components that complement the standard Java framework to automatically integrate log data with Oracle log analysis tools. In the ODL framework, log files are formatted in XML, enabling them to be more easily parsed and reused by other Oracle Application Server and custom-developed components.

The ODL framework provides support for managing log files, including log file rotation. The maximum log file size and the maximum size of log directories can also be defined.

ODL-formatted log files can be viewed through the Web-based Oracle Enterprise Manager 10g Application Server Control, enabling administrators to aggregate and view the logging output generated by all components and applications running within Oracle Application Server from one centralized location. For information about viewing log files generated by an OC4J instance, see the Oracle Containers for J2EE Configuration and Administration Guide.

How Java Logging and Oracle Diagnostic Logging Work Together

In the Java logging framework, applications record events by making calls on Logger objects, which are instances of the java.util.logging.Logger class. A logger is a named entity that is associated with a system or application component. Each logger is assigned a specific log level and records events only at that level of severity or higher.

Logging messages are forwarded to a Handler object, which can in turn forward the messages to a variety of destinations for publication. The oracle.core.ojdl.logging package includes a handler class, ODLHandler, which generates the logger output in XML-based ODL format.

Java Logging Guidelines

The following topics provide guidelines for implementing Java loggers that will integrate with the Oracle Diagnostic Logging framework.

Naming Java Loggers

Java loggers are named entities, named using a hierarchical, dot-separated namespace. The Logger namespace is global, and is shared by all applications running within OC4J. As such, ensure that each logger name is unique to avoid potential naming conflicts.

Each logger name should include the vendor name and component name, and optionally include the module or submodule. Use the following convention for logger names:

vendorName.componentName[.moduleName][.subModuleName]

For example:

acme.mycomponent.mymodule

Setting Log Levels

In the Java logging framework, log levels are represented by objects of the java.util.logging.Level class. This class defines seven standard log levels, ranging from SEVERE (the highest priority, with the highest value) to FINEST (the lowest priority, with the lowest value).

Your applications should utilize these predefined Java log levels, which Oracle diagnostic tools provided as part of OC4J map to Oracle Diagnostic Logging (ODL) message types and levels.

Table 4-1 illustrates the mapping between the predefined Java log levels and ODL message types and levels. The ODL log levels are between 1 and 32, with a lower value indicating a higher severity or less volume of information.

Table 4-1 Mapping Between Java Log Levels and ODL Message Types and Log Levels

Java Log Level ODL Message Type:Log Level ODL Description
SEVERE.intValue()+100
INTERNAL_ERROR:1

The program has experienced an error for some internal or unexpected nonrecoverable exception.

SEVERE
ERROR:1

A problem requiring attention from the system administrator has occurred.

WARNING
WARNING:1

An action occurred or a condition was discovered that should be reviewed and may require action before an error occurs.

INFO
NOTIFICATION:1

A report of a normal action or event. This could be a user operation, such as "login completed" or an automatic operation such as a log file rotation.

CONFIG
NOTIFICATION:16

A configuration-related message or problem.

FINE
TRACE:1

A trace or debug message used for debugging or performance monitoring. Typically contains detailed event data.

FINER
TRACE:16

A fairly detailed trace or debug message.

FINEST
TRACE:32

A highly detailed trace or debug message.


The Oracle diagnostic tools provide some flexibility to accommodate custom log levels implemented with applications. However, containing log levels to the seven default Java levels (SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST) is recommended.

Adding Localization Support

Each Logger object can optionally have an associated ResourceBundle object which is used to localize log message strings.

If a logger does not have an associated ResourceBundle, it will inherit the ResourceBundle name from its parent according to the classic class-loader hierarchy, recursively up the tree.

Configuring Java Loggers to Use the ODL Framework

Enabling Java loggers to output log messages in the ODL format is accomplished by mapping each logger to ODLHandler. This mapping is managed through a logging configuration file, j2ee-logging.xml, which is generated by OC4J in the ORACLE_HOME/j2ee/instance/config directory.

To set the log levels for loggers with Application Server Control:

  1. On the OC4J Home page, click Administration.

  2. From the administration tasks, select Logger Configuration to display the Logger Configuration page.

  3. Click Expand All to view the entire list of loggers currently loaded for the OC4J instance.

  4. Select a log level for any of the loggers listed on the page.

You can also edit the j2ee-logging.xml configuration file by hand. Restart OC4J after making any changes to this file.

This configuration file contains two elements within the <logging-configuration> root element:

The following example shows the definition of ODLHandler and the mapping of the default oracle and custom acme.scheduler loggers to ODLHandler within j2ee-logging.xml.

<logging_configuration>
  <log_handlers>
    <log_handler name='oc4j-handler'
        class='oracle.core.ojdl.logging.ODLHandlerFactory'>
      <property name='path' value='%ORACLE_HOME%/j2ee/log/oc4j'/>
      <property name='maxFileSize' value='10485760'/>
      <property name='maxLogSize' value='104857600'/>
    </log_handler>
  </log_handlers>
  <loggers>
    <logger name='oracle' level='NOTIFICATION:1' useParentHandlers='false'>
      <handler name='oc4j-handler'/>
    </logger>
    <logger name='acme.scheduler' level='TRACE:1' useParentHandlers='false'>
      <handler name='oc4j-handler'/>
    </logger>
  </loggers>
</logging_configuration>

Using Oracle HTTPClient Logging

Oracle HTTPClient, installed as the oracle.http.client:10.1.3 system library, logs activity during setup and communications. HTTPClient version 10.1.3 or later uses the standard JDK logging API (java.util.logging). The HTTPClient root logger is HTTPClient.

You can enable, disable, and control HTTPClient logging in standalone OC4J or in an OC4J instance or group with any of these features:

Also, you can redirect HTTPClient messages to the OC4J log. For information about how to do this, see "Viewing Application Messages in the OC4J Log with LogViewer" in Oracle Containers for J2EE Configuration and Administration Guide.

Enabling HTTPClient Logging with the ODL Framework

You can enable HTTPClient Logging in the j2ee-logging.xml configuration file, using the ODL framework. For information about this file, see"Configuring Java Loggers to Use the ODL Framework".

To enable HTTPClient logging with the ODL framework:

  1. Edit thej2ee-logging.xml logging configuration file for standalone OC4J or an OC4J instance or group.

  2. Map the HTTPClient logger to ODLHandler, like this:

    <logging_configuration>
      <log_handlers>
        <log_handler name='oc4j-handler'
            class='oracle.core.ojdl.logging.ODLHandlerFactory'>
          <property name='path' value='%ORACLE_HOME%/j2ee/log/oc4j'/>
          <property name='maxFileSize' value='10485760'/>
          <property name='maxLogSize' value='104857600'/>
        </log_handler>
      </log_handlers>
      <loggers>
        <logger name='oracle' level='NOTIFICATION:1' useParentHandlers='false'>
          <handler name='oc4j-handler'/>
        </logger>
        <logger name='HTTPClient' level='TRACE:1' useParentHandlers='false'>
          <handler name='oc4j-handler'/>
        </logger>
      </loggers>
    </logging_configuration>
    
  3. Save the j2ee-logging.xml file.

  4. Restart OC4J.

To disable HTTPClient logging with the ODL framework:

  1. Edit thej2ee-logging.xml logging configuration file for standalone OC4J or an OC4J instance or group.

  2. Delete the following HTTPClient logger mapping to ODLHandler from the file:

        <logger name='HTTPClient' level='TRACE:1' useParentHandlers='false'>
          <handler name='oc4j-handler'/>
        </logger>
    
  3. Save the j2ee-logging.xml file.

  4. Restart OC4J.

Enabling HTTPClient Logging for Standalone OC4J or a Client-Side Application with a System Property

You can enable HTTPClient logging for standalone OC4J or client-side applications by setting HTTPClient.log.level to any of these standard trace log levels:


CONFIG
FINE
FINER
FINEST
ALL

For information about these log levels and how they map to ODL message types and log levels, see "Setting Log Levels".

For information how to set log levels in Application Server Control, see "Configuring Java Loggers to Use the ODL Framework".

You can disable HTTPClient logging by setting the HTTPClient.log.level to OFF.

Enabling HTTPClient Logging for an OC4J Instance or Group in Oracle Application Server with a System Property

HTTPClient logging for an OC4J instance or group in Oracle Application Server is the same as for standalone OC4J, except that you have the option of setting Java system properties in the Oracle Process Manager and Notification Server (OPMN) configuration file, opmn.xml. Also, HTTPClient logging is directed to system out, which is written to one of the Oracle Application Server logs.

To enable HTTPClient logging for an OC4J instance or group in Oracle Application Server with a system property:

  1. Open the ORACLE_HOME/opmn/conf/opmn.xml file.

  2. Search for the <process-type> element in which the value of the id attribute matches the name of the OC4J instance or group where you want to enable HTTPClient logging; for example:

    <process-type id="OC4J_Portal" module-id="OC4J">
      <environment>
        <variable id="DISPLAY" value="localhost:0"/>
        <variable id="LD_LIBRARY_PATH" value="/private1/iasinst/OraHome_4/lib32:
          /private1/iasinst/OraHome_4/lib:/private1/iasinst/OraHome_4/network/lib:
          /private1/iasinst/OraHome_4/jdk/jre/lib/sparc"/>
      </environment>
      <module-data>
        <category id="start-parameters">
          <data id="java-options" value="-server
            -Djava.security.policy=/private1/iasinst/OraHome_4/j2ee/OC4J_Portal/config/java2.policy
            -Djava.awt.headless=true -Xmx256m "/>
    
  3. Set the system property to enable HTTPClient logging in the value attribute of the <data> element in which the value of the id attribute is java-options, under the <category> element start-parameters, like this:

    <category id="start-parameters">
          <data id="java-options" value="-server
            -Djava.security.policy=/private1/iasinst/OraHome_4/j2ee/OC4J_Portal/config/java2.policy
            -Djava.awt.headless=true -Xmx256m
            -DHTTPClient.log.level=FINE /> 
    
  4. Start the OC4J instance or group.

  5. Review the HTTPClient log where Oracle Application Server writes to standard out.

    This log might be in ORACLE_HOME/opmn/logs/instance_default_1.

To disable HTTPClient logging for an OC4J instance or group in Oracle Application Server with a system property:

  1. Open the ORACLE_HOME/opmn/conf/opmn.xml file.

  2. Search for the <process-type> element in which the value of the id attribute matches the name of the OC4J instance or group where you want to disable HTTPClient logging.:

  3. Set the HTTPClient.log.level system property to OFF in the value attribute of the <data> element in which the value of the id attribute is java-options, under the <category> element start-parameters, like this:

    <category id="start-parameters">
          <data id="java-options" value="-server
            -Djava.security.policy=/private1/iasinst/OraHome_4/j2ee/OC4J_Portal/config/java2.policy
            -Djava.awt.headless=true -Xmx256m
            -DHTTPClient.log.level=OFF> 
    
  4. Start the OC4J instance or group.