Log4j with xinclude

Hi All,

I am trying to implement logging framework with log4j.xml. Below is a sample of my file. But it is not working as expected. Can anyone tell me how we can do xi:include in log4j2??

<log4j:configuration xmlns:log4j=“http://jakarta.apache.com” xmlns:xi=“XInclude” >

<xi:include href=“/home/jack/logging/appenders.xml”>
<xi:include href=“/home/jack/logging/loggers.xml”>

</log4j:configuration>

Could you explain the reason for using Log4j as logging framework and not wM product suite using OOTB services and custom implementation?

XInclude
XML configuration files can include other files with XInclude. Here is an example log4j2.xml file that includes two other files:

<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
<configuration xmlns:xi="http://www.w3.org/2001/XInclude"
               status="warn" name="XIncludeDemo">
  <properties>
    <property name="filename">xinclude-demo.log</property>
  </properties>
  <ThresholdFilter level="debug"/>
  <xi:include href="log4j-xinclude-appenders.xml" />
  <xi:include href="log4j-xinclude-loggers.xml" />
</configuration>
log4j-xinclude-appenders.xml:

<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
<appenders>
  <Console name="STDOUT">
    <PatternLayout pattern="%m%n" />
  </Console>
  <File name="File" fileName="${filename}" bufferedIO="true" immediateFlush="true">
    <PatternLayout>
      <pattern>%d %p %C{1.} [%t] %m%n</pattern>
    </PatternLayout>
  </File>
</appenders>
log4j-xinclude-loggers.xml:

<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
<loggers>
  <logger name="org.apache.logging.log4j.test1" level="debug" additivity="false">
    <ThreadContextMapFilter>
      <KeyValuePair key="test" value="123" />
    </ThreadContextMapFilter>
    <AppenderRef ref="STDOUT" />
  </logger>
 
  <logger name="org.apache.logging.log4j.test2" level="debug" additivity="false">
    <AppenderRef ref="File" />
  </logger>
 
  <root level="error">
    <AppenderRef ref="STDOUT" />
  </root>
</loggers>

Source: Log4j – Configuring Log4j 2

This is a legacy application.

Thanks Mahesh. It works. :slight_smile:

Regards,
Jacob