26 June 2008

Configuring OC4J log handler to log in plain text format

The default log file format for the OC4J generated logs in the 10.1.3.x release is to use an XML formatted log entry, where a single log entry spans many lines.

As with all things XML this enables the logs to be readily read, queried, etc. with any utility that is compatible with the ODL log format. The ASC log viewer is an example of this -- it renders the log files in a pretty easy to view form, and provides convenience functions such as searching, correlation, etc.

However, for us mere humans, all those extra tags tend to make the log files pretty verbose and difficult to read in realtime using a command like tail.

The ODL logging handler that OC4J uses luckily has an option that causes it to generate into a plain text form instead of the default XML form.

To configure it, you simply need to specify an additional property named "format" and set it to a value of "ODL-Text".

Here's an example of defining a new log_handler and directing it to log to the log.txt file, in text form, maintaining a max file size of 10MB:
<log_handler name="my-text-handler" class="oracle.core.ojdl.logging.ODLHandlerFactory">
<property name="format" value="ODL-Text"/>
<property name="path" value="../log/oc4j/log.txt"/>
<property name="maxFileSize" value="10485760"/>
<property name="maxLogSize" value="104857600"/>
<property name="encoding" value="UTF-8"/>
<property name="supplementalAttributes" value="J2EE_APP.name,J2EE_MODULE.name,WEBSERVICE.name,WEBSERVICE_PORT.name"/>
With the handler in place, you can then configure a logger to use your new handler as follows:
<logger name="oracle" level="finer">
<handler name="my-text-handler"/>
At runtime the log.txt file will contain single line, plain text entries of the form:
[2008-06-26T11:40:59.343+09:30] [classloader] [TRACE] [] [] [tid: 10] [ecid:,0] Ign
oring in /D:/java/oc4j-10134-dev/j2ee/home/config/server.xml entry: code-source /D:/java/oc4j-10134-dev/j2ee/home/jsp/lib/taglib/ojsputil.jar (from in /D:/java/oc4j-10134-dev/j2ee/home/config/server.xml) is already visible in the search path of global.tag.libraries:1.0.


Tony said...

This is excellent stuff, thanks a lot. It may help to point out that in the name of the logger, when being used with JDK logging api, the name matches the hierarchy of the logging message.

Any way to configure it so the tid and ecid are not included in the log output?

Buttso said...

Thanks. Good idea. I'm not sure whether the ECID tag can be removed -- my hunch is its part of the OJDL Logger implementation. Will try and seek out the src code to have a look and see if its configurable.