The latest version of mule esb is supporting the log4j2 . Hope the version may be tightly coupled that could be the reason it might not work.
Question
Does Mule ESB support log4j2? I am trying to add log4j2.xml in my esb app, but even after adding log4j2.xml, my mule esb app is defaulting to its own log4j 1.2 implementation. I want my esb app to read my log4j2.xml file and take/consume in the parameters what I am specifying in my log4j2.xml and if log4j2.xml file is present then it should not read its own log4j 1.2 implementation log properties file.
I am having problem in implementing log4j2(.xml) with mule esb app. Any help would be very much appreciated.
Solution
OTHER TIPS
Log4j2 has an adapter allows application that are coded against the log4j-1.2 API to use the log4j2 implementation. (See also the FAQ.)
Steps to achieve this:
- remove the log4j-1.2.x.jar from the classpath
- add the log4j-1.2-api-2.0.jar jar to the classpath.
- ensure that log4j-api-2.0.jar and log4j-core-2.0.jar are in the classpath
Now both the log4j-1.2 API and the log4j2 API will delegate to the log4j2 implementation. A sample configuration is here.
Log4j2 is implicitly supported from Mule-3.6.0 onwards. For more info please go through this link Asynchronous Logging in Mule
Mule esb supports log4j. check if you have imported slf4j libraries.
You need to create/rename log4j2-test.xml
These are my log4j2.xml and my pom.xml files, I´m using mule v7.1. I hope it helps.
log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="debug">
<Properties>
<Property name="log-path">/my_path/my_logs/my_app</Property>
<Property name="app-id">my_app</Property>
</Properties>
<Appenders>
<RollingFile name="file-log" fileName="${log-path}/${app-id}.log"
filePattern="${log-path}/${app-id}-%d{yyyy-MM-dd}.log">
<PatternLayout>
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1"
modulate="true" />
</Policies>
</RollingFile>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout
pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" />
</Console>
</Appenders>
<Loggers>
<Logger name="org.apache.logging.log4j" level="warn" additivity="false">
<appender-ref ref="file-log" />
<appender-ref ref="console" />
</Logger>
<Root level="info" additivity="false">
<appender-ref ref="file-log" />
<appender-ref ref="console" />
</Root>`enter code here`
</Loggers>
</Configuration>
pom.xml
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0</version>
</dependency>