| Oracle® Containers for J2EE Developer's Guide 10g (10.1.3.4.0) Part Number E12290-01 |
|
|
View PDF |
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.
The Java and Oracle logging frameworks are integrated to enable Java log output to be generated in Oracle format.
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, 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.
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.
The following topics provide guidelines for implementing Java loggers that will integrate with the Oracle Diagnostic Logging framework.
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
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.
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.
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:
On the OC4J Home page, click Administration.
From the administration tasks, select Logger Configuration to display the Logger Configuration page.
Click Expand All to view the entire list of loggers currently loaded for the OC4J instance.
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:
<log_handlers>
This element defines one or more handlers within OC4J. It includes one or more <log_handler> elements, each defining the name of a handler and the class that generates instances of it. By default, this element includes <log_handler> elements defining three different log handlers:
oc4j-handler
This is the log handler for the oracle logger.
oracle-webservices-management-auditing-handler
This is the log handler for the oracle.webservices.management.auditing logger.
oracle-webservices-management-logging-handler
This is the log handler for the oracle.webservices.management.logging logger.
The name of the handler is used only within a <logger> element (described in the following text) to assign the handler to a logger.
The handler class can be either a subclass of java.util.logging.Handler or a class that implements a HandlerFactory interface. If the class is a java.util.logging.Handler subclass, the default constructor for that class will be used to create a handler instance.
If the class implements the HandlerFactory interface, additional configuration properties for the handler can be specified. The only available HandlerFactory class is oracle.core.ojdl.logging.ODLHandlerFactory, which can be used to configure an ODLHandler instance.
The ODLHandlerFactory class accepts the following properties, each specified in a <property> subelement:
path: Specifies the directory in which the handler will generate log files. In the case of ODLHander, the directory specified is the destination for all ODL-formatted logs. Do not modify this value.
maxFileSize: Sets the maximum size, in kilobytes (KB) for any log file in the directory. When a file reaches this limit, a new file is generated.
maxLogSize: Sets the maximum size, in megabytes (MB), allowed for the log file directory. When this limit is exceeded, log files are purged, beginning with the oldest files.
<loggers>
This element defines the mapping between each named logger and the specific handler that will process its messages, including ODLHandler. Each mapping is defined within a <logger> element, which includes the following:
name: The logger name.
level: The minimum log level that this logger acts upon. This level can be either a Java log level (FINE) or an ODL Message Type:Log Level (TRACE:1).
useParentHandlers: Indicates whether or not the logger should use its parent handlers. This value is true by default.
<handler>: The name of a handler to use, as defined in a <log_handler> element. Only handlers defined within a <log_handler> element can be specified.
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>
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:
The Oracle Diagnostic Logging (ODL) framework
ODL works with the Java logging framework to integrate log data with Oracle log analysis tools. Using the ODL framework, you can enable HTTPClient logging in the j2ee-logging.xml configuration file. For information about this file, see "Configuring Java Loggers to Use the ODL Framework" For information about how ODL works with the Java logging framework, see "Overview of the Java and Oracle Logging Frameworks".
The HTTPClient.log.level system property
This system property enables or disables HTTPClient logging with a java.util.logging.Level value. HTTPClient uses only the trace portion of the JDK logging levels because it is a utility library and is unaware of the application context within which an error occurs. It does not use the SEVERE, WARNING, and INFO logging levels, which are reserved for applications.
The Java logging framework
By default, HTTPClient logging is controlled by the JDK java.util.logging properties specified at JVM startup. This is described in the Javadoc output for java.util.logging.LogManager. Usually, the JDK logging properties are configured in the JRE-directory/lib/logging.properties file.
For information about the java.util.logging, package, see "The Java Logging Framework".
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.
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:
Edit thej2ee-logging.xml logging configuration file for standalone OC4J or an OC4J instance or group.
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>
Save the j2ee-logging.xml file.
Restart OC4J.
To disable HTTPClient logging with the ODL framework:
Edit thej2ee-logging.xml logging configuration file for standalone OC4J or an OC4J instance or group.
Delete the following HTTPClient logger mapping to ODLHandler from the file:
<logger name='HTTPClient' level='TRACE:1' useParentHandlers='false'> <handler name='oc4j-handler'/> </logger>
Save the j2ee-logging.xml file.
Restart OC4J.
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:
CONFIGFINEFINERFINESTALLFor 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.
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:
Open the ORACLE_HOME/opmn/conf/opmn.xml file.
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 "/>
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 />
Start the OC4J instance or group.
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:
Open the ORACLE_HOME/opmn/conf/opmn.xml file.
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.:
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>
Start the OC4J instance or group.