webMethods Integration Server version: 10.5 and above
Introduction
There have been many topics discussing in detail about log4j2 configuration, especially Use log4j2 in webmethods which is an excellent read. I would highly recommend anyone to go through the topic to get detailed insights.
Why this article?
This article is intended to be a quick hint to use a logger used in log4j properties file (old format ) in later versions of IS which uses log4j2 properties format which I personally find to be easier to read than the file in XML format ( sorry XML ).
Steps to follow
Log4j
For an existing logger testLog in the log4j properties file
The entries would be
log4j.logger.testLog=INFO, testLoggerRef
log4j.appender.testLoggerRef=org.apache.log4j.RollingFileAppender
log4j.appender.testLoggerRef.File=logs/customLogs/testLogFile.log
( other properties are ignored since there are not vital to this discussion )
The logs are written to a file testLogFile.log under the customLogs folder , i.e., the absolute path /IntegrationServer/instances/<instance_name>/logs/customLogs/testLogFile.log
Log4j2
Under log4j2, to start logging to the log file add the following entries in a customlog4j2.properties file
appender.rolling.type=RollingFile
appender.rolling.name=testLoggerRef
appender.rolling.fileName=logs/customLogs/testLogFile.log
appender.rolling.filePattern=logs/customLogs/testLogFile-%i.log.gz
appender.rolling.layout.type=PatternLayout
appender.rolling.layout.pattern=%date{DEFAULT} %-5level [%-60.60logger{3.1.}]- %message%n
appender.rolling.policies.type=Policies
appender.rolling.policies.size.type=SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=10MB
appender.rolling.strategy.type=DefaultRolloverStrategy
appender.rolling.strategy.max=10
logger.10.name=testLog
logger.10.level=info
logger.10.appenderRef.rolling.ref=testLoggerRef
(Important entries highlighted)
Refer the customlog4j2.properties in the custom_wrapper.conf
Append the filename
wrapper.java.additional.xxx=-Dlog4j.configurationFile= … , customlog4j2.properties
Does this work?
To verify, simply add the following lines in a java service and run
Imports
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
Service Name
logToTestLog(IData pipeline){
Logger logger = LogManager.getLogger("testLog");
logger.error("This is an error message");
logger.info("This is an INFO message");
}
The testLogFile.log will have entries
ERROR [testLog ] - This is an Error message
INFO [testLog ] - This is an Info message
Next steps
Happy Logging
Useful links | Relevant resources
Log4j2 documentation