Wednesday, September 1, 2010

Generating custom logs with Log4J within Java Embedding activity

To generate custom logs within a BPEL process using a Java Embedding activity and Log4J do the following steps:
  • Copy log4j-1.2.15.jar to <oss_home>/soa/modules/oracle.soa.ext_11.1.1 and execute ANT script in this directory. This will recreate the oracle.soa.ext.jar file adding the log4j lib to the classpath.
  • Create a new folder for Log4j configuration and log files: <middleware_home>/config, for example
    • add to this folder the configuration files (log4j.debug.xml and log4j.dtd, for example)
    • set the log file name and path (<middleware_home>/config/customErrorLog.log, for example) in the log4j.debug.xml
  • Change the startManagedServer script to point to Log4j configuration file: JAVA_OPTIONS="-Dlog4j.configuration=file:<middleware_home>/config/log4j.debug.xml”
  • Restart the SOA managed server.
From a BPEL development perspective, what is necessary to do is:
  • Import the log4j-1.2.15.jar to the project libs (right click in the project name and select “Project Properties”, go to “Libraries and Classpath” and add the jar file)
  • Insert a Java Embedding activity
  • In the BPEL source code, import the Logger class adding the code below before the “bpelx:exec” created for the Java Embedding component
  • <bpelx:exec import="org.apache.log4j.Logger">
  • Edit the Java Embedding activity and insert the necessary log instructions like:
  • Logger logger = Logger.getLogger("myCustomLog");">>>> Message log for instance: " + getTitle());

To download the Log4j configuration files together with a Composite with a sample use of the log, click here.


  1. very interesting. They say that addAuditTrailEntry is very heavy, so using log4j might prove very effective

  2. Hi,

    how can we implement the same in bpel 10g.
    It would be great if you throw some light.