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.
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
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.
Replace this slf4j-jdk14-1.7.12.jar file with SLF4J-Log4j binding jar file
Add Log4j required core library files to the Java classpath
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:
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"?>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="current date-%d LEVEL-%-5p Thread-[%t] Method-%M() Class name-%C Message-%m%n"/>
<Logger name="org.apache.log4j.xml" level="all"/>
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-188.8.131.52.jar;..\libs\eta-184.108.40.206.jar;..\libs\etaValueAdd-220.127.116.11.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
Text: Print out active configuration detail.
current date-2020-12-15 15:37:00,382 LEVEL-TRACE Thread-[main] Method-<init>() Class name-com.refinitiv.ema.access.CallbackClient Message-loggerMsg
Text: Created LoginCallbackClient
current date-2020-12-15 15:37:00,382 LEVEL-TRACE Thread-[main] Method-initialize() Class name-com.refinitiv.ema.access.LoginCallbackClient Message-loggerMsg
Text: RDMLogin request message was populated with this info:
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
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.
For further details, please check out the following resources:
- Refinitiv Real-time Java API page on the Refinitiv Developer Community web site.
- Simple Logging Facade for Java (SLF4J) web site.
- Apache Log4j 2 web site. For further details, please check out the following resources:
- Enterprise Message API Java Quick Start
- Developer Webinar: Introduction to Enterprise App Creation With Open-Source Enterprise Message API
For any question related to this article or Enterprise Message API page, please use the Developer Community Q&A Forum.