log4j2.xml configuration from file for mule applications in mule 3.6.2

陌路散爱 提交于 2019-12-14 00:27:43

问题


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.


回答1:


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> 


来源:https://stackoverflow.com/questions/33423298/log4j2-xml-configuration-from-file-for-mule-applications-in-mule-3-6-2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!