Other recent blogs
Let's talk
Reach out, we'd love to hear from you!
Log4J is a Java-based framework that can be integrated with various platforms and used for custom logging purposes. An upgrade to Log4J with significant improvements, Version 2.x is garbage-free and logs asynchronously using LMAX Disruptor, thereby resulting in low latencies and increased throughput.
Why Log4J?
Log4J is an independent logging mechanism for webMethods environment. Using custom logs, developers find it easier to log the entry/exit point of each service with the request and response XML. These are also helpful in identifying WARN, INFO, FATAL, ERROR, and DEBUG logs.
Integrating Log4J2 with webMethods
Below is the step-by-step guide to performing smooth integration of Log4J2 with webMethods.
Technologies used:
- webMethods Integration Server 9.X
- Jog4J2 Package and log4j2.xml file
- JAR files to place in the Integration Server classpath
Step 1: Install Log4J webMethods Package
Install the Log4J webMethods package in the webMethods Integration Server. You can download it here: Download
Step 2: Define Appenders and Loggers
Edit the "log4j2.xml" file as per your environment and configuration, and place the "log4j2.xml" file in the "...\SoftwareAG\IntegrationServer\instances\default\config" location
The screenshot below shows you the basic environment changes:
Log4J provides default Appenders that manage logging of messages to multiple targets. It also provides asynchronous and synchronous loggers.
The user can create custom Appenders and Loggers. If custom Appenders and Loggers are absent in the "log4j2.xml" file, Log4J will automatically provide the default configuration and will log the data to default folder mentioned in the "log4j2.xml" file.
The screenshot below displays the Default Appender and custom demo Appender.
Step 3: Enable reading of Log4J2.xml through Log4J Wrapper Configurations
Edit the "...\SoftwareAG\profiles\IS_default\configuration\custom_wrapper.conf" file and copy the below settings as shown in the below screenshot:
wrapper.java.additional.204=-Dlog4j.configurationFile=file:///c:/SoftwareAG/IntegrationServer/instances/default/config/log4j2.xml
wrapper.java.additional.205=-DAsyncLogger.RingBufferSize=132000
wrapper.java.additional.206=-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
wrapper.java.additional.302=-DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
Step 4: Configure Environment Variables
Edit the "...\SoftwareAG\profiles\IS_default\bin\setenv.bat" file and copy the below settings as shown in the screenshot
SET JAVA_CUSTOM_OPTS=-Dlog4j.configurationFile=file:///c:/SoftwareAG/IntegrationServer/instances/default/config/log4j2.xml -DAsyncLogger.RingBufferSize=132000 -Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
Step 5: Execute Log4J2 JAR Files
Copy the latest "log4j-api-2.8.2.jar," "log4j-core-2.8.2.jar" and "disruptor-3.3.4.jar" (Check for the mentioned JARs in the web for the latest version) files to
"...\SoftwareAG\IntegrationServer\instances\default\packages\Log4j\code\jars" location
Step 6: Activate Log4J2 Logging in webMethods
After completing the above five steps, shutdown and start (do not restart option) the Integration Server.
Implement logging by using the Log4J flow services in the "Log4j" package. You can implement custom logging as per your requirements by making changes to the configuration file and using the flow services in the "Log4j" package.
Use "Log4j.base.services:logMessage" service for log testing. The flowchart below explains the high-level logic of this wrapper service as implemented by us.
The screenshot below shows the data logged into the file at the location specified in the "log4j2.xml" file.