This recipe explains how to configure different logging handlers in the Oracle SOA Suite. Although many of the logging handlers already exist, occasionally we may need some special functionality, such as the ability to log into databases or logging via web services. The number of log handler classes in the Oracle SOA Suite is quite limited. Actually, if you check the logging.xml
file, you'll only find two types: oracle.core.ojdl.weblogic.DomainLogHandler
and oracle.core.ojdl.logging.ODLHandlerFactory
. For this recipe, we will define a custom handler and use it in our configuration. The custom handler will enable each instance of the BPEL process to log into its own logfile.
The following steps describe the actions required to create and configure a custom log handler:
CustomLogger.java
) in the logging
package as shown in the following code:package logging; public class CustomLogger extends Handler {
java.util.logging.Handler
, which presents the default template class to design the new log handlers. CustomLogger
will create a logfile in the Java temp
directory and name it with your computer name and append the extension log
to it.FileOutputStream fileOutputStream; PrintWriter printWriter;
InetAddress iAddress = InetAddress.getLocalHost(); String hostName = iAddress.getHostName(); String tempDir= System.getProperty("java.io.tmpdir"); String fileLoc= tempDir + hostName + ".log"; And finally create concrete output streams: fileOutputStream = new FileOutputStream(fileLoc); printWriter = new PrintWriter(fileOutputStream);
publish
method, which is used to write data to the file as shown in the following code:public void publish(LogRecord record) { if (!isLoggable(record)) return; printWriter.println (getFormatter().format(record)); }
flush
method because we need to flush the content to the output stream as shown in the following code:public void flush() { printWriter.flush(); }
close
method as shown in the following code:public void close() { printWriter.close(); }
deploy
directory of the project.${domain.home}/lib
logging.xml
file that holds the logging configuration at the following path:${domain.home}configfmwconfigserversAdminServerlogging.xml
logging.xml
file and define a new log handler inside it as shown in the following code:<log_handler name='custom-java-handler' class='logging.CustomLogger' level='TRACE:32' formatter='java.util.logging.SimpleFormatter'/>
We can see that the handler as well as the formatter belongs to the Java Logging utility.
<log_handler>
element as shown in the following code:<logger name='' level='WARNING:1'> <handler name='odl-handler'/> <handler name='wls-domain'/> <handler name='console-handler'/> <handler name='custom-java-handler'/> </logger>