Article

How to integrate Enterprise Message API Java edition with Log4j Logging Framework

Wasin Waeosri
Developer Advocate Developer Advocate

Overview

Update: January 2022

As of December 2021: There are new serious vulnerabilities that were identified impacting the Apache Log4j utility. Please update the library to the latest version. You can find more detail regarding the vulnerability and the fix from the Apache Log4j Security Vulnerabilities page.

Enterprise Message API - Java Edition (EMA API) allows developers to integrate the EMA Java application with Apache Log4j which is a de facto standard logging framework for Java-based applications at deployment time by using the Simple Logging Facade for Java (SLF4J) API as a facade for logging utility.

Even though the EMA Java API binds the logging mechanism with Java Logging API by default, developers can change the binding library and logging configuration files to bind the EMA Java application with Log4j or another framework that supported SLF4J without modifying the application source code.

The article is focusing on how to integrate Log4j with the EMA Java application in a manual way which is suitable for earlier versions of EMA Java API. However, the API has been mavenized to support the Apache Maven and Gradle build tools since Refinitiv Real-Time SDK (RTSDK) Java (formerly known as Elektron SDK) version 1.2, if you are using Maven, please check this How to integrate Enterprise Message API Java with Log4j Logging Framework using Maven article.

IMPORTANT Rebranding Announcement:

Starting with version RTSDK 2.0.0.L1 (same as EMA/ETA 3.6.0.L1), there are namespace changes and library name changes. Please note that all interfaces remain the same as prior releases of RTSDK and Elektron SDK and will remain fully wire compatible. Along with RTSDK 2.X version, a REBRAND.md is published to detail impact to existing applications and how to quickly adapt to the re-branded libraries. Existing applications will continue to work indefinitely as-is. Applications should be proactively rebranded to be able to utilize new features, security updates or fixes post 2.X release. Please see PCN for more details on support.

Building RTSDK

Please follow the steps in Building RTSDK to build RTSDK jar files.

How to integrate EMA Java Application with Logging Framework

The RTSDK Java package contains two SLF4J library files in the <Real-Time SDK Java 2.0.0.L1 package>/RTSDK-BinaryPack/Java/Eta/Libs/SLF4J/slf4j-1.7.12 folder

  • slf4j-api-1.7.12.jar

  • slf4j-jdk14-1.7.12.jar

The slf4j-api-1.7.12.jar file is the core SLF4J library file. The slf4j-jdk14-1.7.12.jar is a binding library file for Java Logging API. Developers can perform the following steps to integrate the EMA Java application log with Log4j framework.

  1. Replace this slf4j-jdk14-1.7.12.jar file with SLF4J-Log4j binding jar file

  2. Add Log4j required core library files to the Java classpath

  3. Configure configurations file to Java classpath or JVM option

Integration with Log4j 2 framework

The Log4j 2 framework requires the following libraries files in Java classpath to intergrate with EMA Java SLF4J framework:

  • log4j-api-<version>.jar
  • log4j-core-<version>.jar
  • log4j-slf4j-impl-<version>.jar
  • slf4j-api-<version>.jar

Then developers can configure Log4j 2 configurations file to Java classpath or JVM option "-Dlog4j.configurationFile" at runtime to let the EMA Java application uses Log4j 2 configurations file.

This article is based on Log4j 2.

Example Log4j 2 configurations file (in XML format)

The example file is saved as "\resource\log4j2.xml" file.

    	
            

<?xml version="1.0" encoding="UTF-8"?>

<Configuration>

    <Appenders>

        <Console name="STDOUT" target="SYSTEM_OUT">

            <PatternLayout pattern="current date-%d LEVEL-%-5p Thread-[%t]  Method-%M()   Class name-%C   Message-%m%n"/>

        </Console>

    </Appenders>

    <loggers>

        <Logger name="org.apache.log4j.xml" level="all"/>

        <root level="all">

            <appender-ref ref="STDOUT"/>

        </root>

    </loggers>

</Configuration>

Then you can run the EMA Java example with JVM option -Dlog4j.configurationFile points to the log4j2.xml file and include the Log4j 2 libraries files in the Java classpath too.

Examples Directory structure:

  • All RTSDK jars files and dependencies are available in libs folder.
  • The EmaConfig.xml file and compiled EMA Java example class files are available out folder.
    	
            
java -Dlog4j.configurationFile=..\resources\log4j2.xml -cp .;..\libs\ema-3.6.0.0.jar;..\libs\eta-3.6.0.0.jar;..\libs\etaValueAdd-3.6.0.0.jar;..\libs\commons-collections-3.2.2.jar;..\libs\commons-configuration-1.10.jar;..\libs\commons-lang-2.6.jar;..\libs\commons-logging-1.2.jar;..\libs\httpclient-4.5.3.jar;..\libs\httpcore-4.4.12.jar;..\libs\slf4j-api-1.7.12.jar;..\libs\log4j-api-2.17.1.jar;..\libs\log4j-core-2.17.1.jar;..\libs\log4j-slf4j-impl-2.17.1.jar; com.refinitiv.ema.examples.training.consumer.series100.ex100_MP_Streaming.Consumer

An example result with Log4j 2 is shown below:

    	
            

current date-2020-12-15 15:37:00,156 LEVEL-TRACE Thread-[main]  Method-initialize()   Class name-com.refinitiv.ema.access.OmmBaseImpl   Message-loggerMsg

    ClientName: Consumer_1_1

    Severity: Trace

    Text:    Print out active configuration detail.

     itemCountHint: 100000

     serviceCountHint: 513

     requestTimeout: 15000

     dispatchTimeoutApiThread: 0

     maxDispatchCountApiThread: 100

     maxDispatchCountUserThread: 100

     userDispatch: 1

     configuredName: Consumer_1

     instanceName: Consumer_1_1

     xmlTraceEnable: false

     globalConfig.reactorChannelEventPoolLimit: -1

     globalConfig.reactorMsgEventPoolLimit: -1

     globalConfig.workerEventPoolLimit: -1

     globalConfig.tunnelStreamMsgEventPoolLimit: -1

     globalConfig.tunnelStreamStatusEventPoolLimit: -1

     obeyOpenWindow: 1

     postAckTimeout: 15000

     maxOutstandingPosts: 100000

     userDispatch: 1

     reconnectAttemptLimit: -1

     reconnectMinDelay: 1000

     reconnectMaxDelay: 5000

     msgKeyInUpdates: true

     directoryRequestTimeOut: 45000

     dictionaryRequestTimeOut: 45000

     reissueTokenAttemptLimit: -1

     reissueTokenAttemptInterval: 5000

     restRequestTimeOut: 45000

     tokenReissueRatio: 0.8

     loginRequestTimeOut: 45000

loggerMsgEnd

 

....

 

current date-2020-12-15 15:37:00,382 LEVEL-TRACE Thread-[main]  Method-<init>()   Class name-com.refinitiv.ema.access.CallbackClient   Message-loggerMsg

    ClientName: LoginCallbackClient

    Severity: Trace

    Text:    Created LoginCallbackClient

loggerMsgEnd



current date-2020-12-15 15:37:00,382 LEVEL-TRACE Thread-[main]  Method-initialize()   Class name-com.refinitiv.ema.access.LoginCallbackClient   Message-loggerMsg

    ClientName: LoginCallbackClient

    Severity: Trace

    Text:    RDMLogin request message was populated with this info: 

    LoginRequest: 

    streamId: 1

    userName: user

    streaming: true

    nameType: 1

    applicationId: 256

    applicationName: ema

    position: 192.168.68.113/WIN-V793K3HCLOL

 

loggerMsgEnd

Integration with Log4j 1.x framework

On August 5, 2015 the Logging Services Project Management Committee announced that Log4j 1.x had reached end of life. For complete text of the announcement please see the Apache Blog. Users of Log4j 1 are recommended to upgrade to Apache Log4j 2

Conclusion

The EMA Java API is implemented on top of SLF4J API as a facade for logging utility. It allows developers to integrate EMA Java application with their preferred Logging framework by replacing the Logging library and configuration files without touching the application source code.

References

For further details, please check out the following resources:

For any question related to this article or Enterprise Message API page, please use the Developer Community Q&A Forum.