As any good developer or administrator will tell you, comprehensive and flexible logging and debugging facilities go a long way to making their lives easier. Good logging and debugging facilities helps them to quickly track down and identify when and why an unexpected result or situation is occurring. Oracle9iAS Containers for J2EE (OC4J) provides these types of logging and debugging facilities. It enables the logging of specific events, errors, and exceptions that may be useful in troubleshooting problems. Similarly, it also enables the setting of specific debugging options to display details on what is happening behind the scene as as applications are running. In this article we will discuss the logging and debugging facilities in OC4J you can use.
OC4J is available in two different forms:
The capabilities and techniques used for logging and debugging are slightly different when using the standalone model and the Oracle9iAS model. In this technical note, we will discuss how can you configure and use logging and debugging in both environments.
OC4J provides several log files that record events generated by the OC4J runtime and applications that have been deployed.. The following table lists the log files.
| Default
Log File Name |
Description |
Scope |
Configuration File | Comments |
| appplication.log | All events, errors, and exceptions for a deployed application | One log file for each application deployed | orion-application.xml | Very useful for developers |
| global-application.log | All common events, errors, and exceptions related to applications |
All applications Default application |
application.xml | |
| jms.log | All JMS events and errors | JMS sub-system | jms.xml | |
| rmi.log | All RMI events and errors | RMI subsystem | rmi.xml | |
| server.log | All events not associated with a particular subsystem or an application | Server wide | server.xml | This logs history of Server startup Server shutdown Internal server errors |
| web-access.log | Logs all web accesses | Each website | web-site.xml | Not useful for debugging purposes. |
The location of all of the above log files can be specified (except the web-access.log)
using the <log> tag in the respective configuration files.
For example you can specify the the server log file to use in the server.xml
configuration file.
<log>
<file path="../log/debu-server.log" />
</log>
You can also specify an absolute path for the location of the log file
<log>
<file path="d:\log-files\Debu-server.log" />
</log>
The following table shows the default location for the log files for a standalone OC4J. You can modify the location and names of these files by making changes in the configuration files as described in the previous section.
| Log File |
Default Location |
| appplication.log | <install_dir>/j2ee/home/application-deployments/<application-name> |
| global-application.log | <install_dir>/j2ee/home/log |
| jms.log | <install_dir>/j2ee/home/log |
| rmi.log | <install_dir>/j2ee/home/log |
| server.log | <install_dir>/j2ee/home/log |
Many developers use the System.out.println() and System.err.println()
methods in their applications to generate debugging formation. Normally
the output from these method calls go to the console where the OC4J process
is started. However you can specify command line options when starting OC4J
to direct the stdout and stderr output directly to files. The ?out
and ?err parameters tell OC4J which file to direct the
$ java -jar oc4j.jar -out d:\log-files\oc4j.out -err d:\log-files\oc4j.err
In this case all information written to stdout and stderr will be stored in the files d:\log-files\oc4j.out and d:\log-files\oc4j.err respectively.
In an Oracle9iAS environment,
an OC4J instance can is created and managed from the Enterprise Manager console.
An OC4J instance can be configured to run as a single process or as multiple
processes - think of an OC4J instance as a set of configuration files, and the
OC4J processes simply as a set of runtimes that share the configuration information
and deployed applications. The OC4J processes are managed by OPMN. Each OC4J
process will have a set of log files. If there are multiple processes running
for an OC4J instance, there will be multiple set of log files. The following
table shows the default location for log files for an OC4J process
| Log File |
Default Location |
| appplication.log | $ORACLE_HOME/j2ee/<OC4J InstanceName>/application-deployments/<application-name>/<OC4J IslandName> |
| global-application.log | $ORACLE_HOME/j2ee/<OC4J InstanceName>/log/<OC4J IslandName>_<Process#> |
| jms.log | $ORACLE_HOME/j2ee/<OC4J InstanceName>/log/<OC4J IslandName>_<Process#> |
| rmi.log | $ORACLE_HOME/j2ee/<OC4J InstanceName>/log/<OC4J IslandName>_<Process#> |
| server.log | $ORACLE_HOME/j2ee/<OC4J InstanceName>/log/<OC4J IslandName>_<Process#> |
| opmn log file for an OC4J process |
$ORACLE_HOME/opmn/logs/<OC4J_Instance_Name>.<Island_Name>.<Process#> |
In an Oracle9iAS environment,
the standard output and standard errors for OC4J are routed to the OPMN log
for the OC4J instance. For example, if you have an OC4J instance called OC4J_Demos,
and it has an island called default_island, and there is only one process
in the island, the file that will contain the stdout, stderr streams will be
$ORACLE_HOME/opmn/logs/OC4J_Demos.default_island.1
You can specify the ?out and ?err parameters in an
Oracle9iAS environment
by specifying a set of OC4J options for your OC4J Instance. This is shown in
Figure 1. When you specify these parameters without specifying a specific directory,
the log files will be created in the $ORACLE_HOME/j2ee/home/<OC4J InstanceName>_<Island
Name>_<Process#> directory.
For example, if you have an OC4J instance called OC4J_Demos and it has
an island called default_island, then the log file will be created in
the $ORACLE_HOME/j2ee/home/OC4J_Demos_default_island_1
In the preceding examples it is assumed that there is only one OC4J process
for the default island. If there are more processes for an island there are
separate log files for each OC4J process.
Fig 1: EM Console to modify Server Properties for an OC4J instance
OC4J provides several debug options for you to use to generate additional information
on the operations performed by the various sub-systems of OC4J. These debug
options can be set for a particular sub-system while starting up OC4J either
in standalone or in an Oracle9iAS
environment. Following are few debug options available with Oracle9iAS
Release 2. Please note that some of these debug options may become obsolete
in future releases of Oracle9iAS
or Oracle may introduce completely different mechanism for debugging in future.
Also worth noting is that turning on excessive debug options can potentially
slow down the execution of your applications and use
The following table provides the different debug options that available with OC4J. These debug options have two states either true or false. By default these are set to false.
| HTTP Debugging | |
| http.session.debug | Provides information about HTTP session events |
| http.cluster.debug |
Provides information about HTTP clustering events |
| http.error.debug |
Prints all HTTP errors |
| JDBC Debugging | |
| datasource.verbose |
Provides verbose information on creation of data source and connections using Data Sources and connections released to the pool, etc, |
| jdbc.debug |
Provides very verbose information when JDBC calls are made |
| EJB Debugging | |
| ejb.cluster.debug | Turns on EJB clustering debug messages |
| transaction.debug |
Provides debug information on transactions, useful for JTA debugging |
| RMI Debugging | |
| rmi.debug |
Prints RMI debug information |
| rmi.verbose |
Provides
very verbose information on RMI calls |
| JMS Debugging | |
| jms.debug |
Prints JMS debug information |
In addition to the specific sub-system switches, you can also start OC4J with a supplied verbosity level. The verbosity level is an integer between 1 and 10. For example you can start OC4J standalone as follows:
java -jar oc4j.jar -verbosity 5
The higher the verbosity level, the more information that is printed in the console. In an Oracle9iAS environment you can specify the verbosity level using EM in the OC4J options area. An example of the output provided at verbosity level 5 is shown below.
D:\java\oc4j-902-production\j2ee\home>java -jar oc4j.jar -verbosity 5
Application default (default) initialized...
Application cmpapp (cmpapp j2ee application) initialized...
Application threadload (ThreadLoad Test) initialized...
Application fiscus-bean (fiscus-bean) initialized...
Application TestFilter (webapp1) initialized...
Web-App default:defaultWebApp (0.0.0.0/0.0.0.0:8888) started...
Oracle9iAS (9.0.2.0.0) Containers for J2EE initialized
You can start OC4J with one or more debug options. The default
value for the debug options is false and must be explicitly set to true to become
active. For example, if you want to generate debug information on HTTP session
events then you will start OC4J as follows:
java -Dhttp.session.debug=true -jar oc4j.jar
After OC4J is started with a specific debug option, debug information will be generated and routed to standard output. For example you will see HTTP session information on your OC4J console as follows:
If you want to save this debug information you can redirect your standard output to a file. For example
Oracle9iAS (9.0.2.0.0) Containers for J2EE initialized
Created session with id '36c04d8a1cd64ef2b6a9ba6e2ac6637e' at Mon Apr 15 12:24:20 PDT 2002, secure-only: false
Created session with id '36c04d8a1cd64ef2b6a9ba6e2ac6637e' at Mon APR 15 12:36:06 PDT 2002, secure-only: false
Invalidating session with id '36c04d8a1cd64ef2b6a9ba6e2ac6637e' at Mon APR 15 12:44:32 PDT 2002
(created at Mon APR 15 12:24:23 PDT 2002) due to timeout
java -Dhttp.session.debug=true -jar oc4j.jar -out oc4j.out -err oc4j.err
By default the debug information will be written to the OPMN log file for the
OC4J instance. This log file normally resides in the $IAS_HOME/opmn/logs/ directory. For example
you have a OC4J instance named OC4J_DEMOS and there is only one island and the
island has only process for this OC4J instance these debug information will
be logged in $IAS_HOME/opmn/logs/OC4J_Demos.default_island.1
However if there is ?out and ?err parameters
specified with OC4J as depicted in Fig 1 then these debug information will be
redirected to the appropriate files.
Now that we have learnt the debugging options in OC4J we take
a loot at some scenarios to see where and how to set helpful debugging options.
Let?s assume that you have deployed a web application to OC4J and you are having
some problems with the Servlets. For example, you are losing the client session
when you use a pre-configured DataSource to make database connection. You want
to know what OC4J is doing when the Servlet is accessing the DataSource. In
order to generate the debug information on HTTP Session and DataSource usage
you need to set two debug options - http.session.debug and datasource.verbose to true.
For the standalone OC4J, you can set these debug options on the command line
when you start OC4J as follows:
java -Dhttp.session.debug=true -Ddatasource.verbose=true -jar oc4j.jar
For OC4J in an Oracle9iAS R2 environment you have to perform the following
tasks
1) Logon to EM console as administrator.
2) Select the OC4J instance from IAS Home Page in EM
3) Then select the Server properties for the OC4J instance and you will get a screen as in Fig 1.4) Then
enter Java Options as follows: -Dhttp.session.debug=true -Ddatasource.verbose=true
5)
Restart the OC4J instance
After the OC4J instance is restarted you can execute your servlet and you will see the following type of debug information in the standard output for the OC4J instance
DataSource logwriter activated... jdbc:oracle:thin:@localhost:1521:DEBU: Started
jdbc:oracle:thin:@localhost:1521:DEBU: Started
Oracle9iAS (9.0.2.0.0) Containers for J2EE initialized
Created session with id '4fa5eb1b9a564869a426e8544963754f' at Tue APR 23 16:22:56 PDT 2002, secure-only: false
Created new physical connection: XA XA Orion Pooled jdbc:oracle:thin:@localhost:1521:DEBU
null: Connection XA XA Orion Pooled jdbc:oracle:thin:@localhost:1521:DEBU allocated (Pool size: 0)
jdbc:oracle:thin:@localhost:1521:DEBU: Opened connection
Created new physical connection: Pooled oracle.jdbc.driver.OracleConnection@5f18
Pooled jdbc:oracle:thin:@localhost:1521:DEBU: Connection Pooled oracle.jdbc.driver.OracleConnection@5f1832 allocated (Pool size: 0)
Pooled jdbc:oracle:thin:@localhost:1521:DEBU: Releasing connection Pooled
oracle.jdbc.driver.OracleConnection@5f1832 to pool (Pool size: 1)
null: Releasing connection XA XA Orion Pooled jdbc:oracle:thin:@localhost:1521:DEBU to pool (Pool size: 1)
Orion Pooled jdbc:oracle:thin:@localhost:1521:DEBU: Cache timeout, closing connection (Pool size: 0)
com.evermind.sql.OrionCMTDataSource/default/jdbc/OracleDS: Cache timeout, closing connection (Pool size: 0)
You can remotely debug your applications deployed in OC4J using any Java debugging facility that supports the JPDA (Java Platform Debugging Architecture). Oracle's great Java IDE, Oracle9i JDeveloper, provides a very convenient and feature rich debugging environment for OC4J. With OC4J being embedded directly inside of the Oracle9i JDeveloper IDE, debugging both locally deployed and remote J2EE applications is a snap. For more details, please see the Oracle9i JDeveloper documentation or take a look at the Remote Debugging How-To documents that are posted on OTN.
In this article we discussed how can you use different logging and debugging facilities in OC4J. Inappropriate and excessive use of debugging and logging and slow down your OC4J server and applications so use these options in an intelligent manner only when you require them.