Configure ADF12c application to work with log4j2

One of our customers had the requirement to use log4j 2 in his ADF 12c application. When executing his code

[code language=“java“]import java.io.Serializable;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import javax.faces.event.ActionEvent;
import oracle.adf.view.rich.component.rich.input.RichInputText;

public class LoggingBean implements Serializable {
private static final long serialVersionUID = 1L;
private static final Logger log = LogManager.getLogger(LoggingBean.class.getName());

public LoggingBean() {
}

public void logText(ActionEvent actionEvent) {
log.info(„Text to log“);
}

}
[/code]

an UnsupportedOperationException was thrown.

[code language=“xml“][…] Caused by: java.lang.UnsupportedOperationException: setXIncludeAware
is not supported on this JAXP implementation or earlier:
class oracle.xml.jaxp.JXDocumentBuilderFactory
at javax.xml.parsers.DocumentBuilderFactory.setXIncludeAware(DocumentBuilderFactory.java:614)
[/code]

To resolve this issue you can configure your ADF12c application to use a specific implementation of DocumentBuilderFactory. This is quite simple and straightforward. Just configure your weblogic specific deployment descriptor tor use com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl as application’s DocumentBuilderFactory implementation. This is what worked for us. Other implementations of DocumentBuilderFactory might be a valid, too. To configure the DocumentBuilderFactory you can use JDeveloper tooling:

weblogic-application_docbuild

This will put the following lines into your weblogic-application.xml:

[code language=“xml“]

com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl

[/code]

To dodge possible other unsupported operations, we also provided values for SAX Parser Factory and Transformer Factory:

  • SAX Parser Factory: com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
  • Transformer Factory: com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl

The screenshot below shows our configuration:

weblogic-application.xml

Prerequisites

The following JARs have been added to project’s classpath:

  • log4j-api-2.1.jar
  • log4j-core-2.1.jar
  • log4j-web-2.1.jar

These files are contained within the log4j2 download package.

Follow ups

Without providing any configuration file log4j2 will log our messages on console. To configure another behavior just put a configuration file into your project’s src directory (e.g. /Model/src or /ViewController/src).  The  configuration file itself can be written in XML, JSON, or YAML. For more information on the expected syntax have a look at log4j2’s official documentation.

6 Kommentare

  1. Thanks this really helped save my time debugging why I was getting this error

  2. Pingback: WebLogic Partner Community Newsletter December 2014 | WebLogic Community

  3. Pingback: Using log4j 2 in an Oracle ADF 12c Application by Cattle Crew | WebLogic Community

  4. Naveen Darisi Reply

    Hi,

    Thanks for this blog. This helped me in setting up the log4j in adf.

    Can you let me know if it recommended to use this fix in the production.

    Thanks,
    Naveen Darisi

    • Hi Naveen,

      as this just configures ADF application to use a specific implementation of DocumentBuilderFactory, you can use it in production. Don’t let the „internal“ part of the package-qualified class name annoy you.

      But let me go one step back: Why do you want to use log4j/log4j2 instead of ADF Logger? The customer mentioned in the blog had specific requirements (e.g. asynchronous logging on different target filesystems etc.) that were better covered by log4j2.

      Choose your logging technology depending on your use case:

      Pros to use ADFLogger:
      – You can control trace level with a visual interface (Oracle Fusion Middleware Console / Enterprise Manager).
      – ADF logger provides more trace levels than log4j.
      – You have support by Oracle

      Pros to use log4j/log4j2
      – Easy to set different log strategies and file sizes.
      – Great performance / async logging
      – Standard in java ecosystem

      Hendrik

  5. Naveen Darisi Reply

    Hi Hendrik,

    Thanks for confirming.

    My customer is planning to purchase the license for ADFEssentials that doesn’t include the ADF loggers. So I’have tried using the log4j2 as an alternative.

Schreibe einen Kommentar