log4j2.xml configuration from file for mule applic

2019-04-15 12:51发布

How can I get the configuration from a specific file like '/opt/applications/app1/log/config/log4j2.xml' for a mule application in mule 3.6.2. The common way is to get the configuration from a config file log4j2.xml which is stored in the resource folder, we need to read this configuration file from other external path.

标签: mule log4j2
1条回答
Deceive 欺骗
2楼-- · 2019-04-15 13:34

By default, Mule use its own log4j2 file for logging. To read log4j2.xml configuration file from external path, add the next beans in your file Application Context, For that specify the external file to be used in the context General of Mule.

Application Context:

     <bean id="loggerContext" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetClass">
          <value> org.apache.logging.log4j.LogManager</value>
        </property>
        <property name="targetMethod">
          <value>getContext</value>
        </property>
        <property name="arguments">
          <value>false</value>
        </property>
      </bean>

      <bean id="loggerContext1" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetObject" ref="loggerContext" />
        <property name="targetMethod">
          <value>setConfigLocation</value>
        </property>
        <property name="arguments">
          <value>${log4j.external.path}</value>
        </property>
      </bean>

      <bean id="loggerContext2" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetObject" ref="loggerContext" />
        <property name="targetMethod">
          <value>reconfigure</value>
        </property>
      </bean>

Then you need to import this context from your file Mule flow, with:

Mule Config

 <mule xmlns:https="http://www.mulesoft.org/schema/mule/https"
            xmlns="http://www.mulesoft.org/schema/mule/core"
    {..}
   <!-- Add this: -->
    <spring:beans>
        <spring:import resource="classpath*:application-context.xml" />
    </spring:beans>
    {..}
    <flow name="http-name" >
        {..}
    </flow> 
</mule> 
查看更多
登录 后发表回答