在mule 3.6.2中,log4j2.xml配置来自mule应用程序的文件。[英] log4j2.xml configuration from file for mule applications in mule 3.6.2

本文是小编为大家收集整理的关于在mule 3.6.2中,log4j2.xml配置来自mule应用程序的文件。的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

如何从特定文件中获取诸如mule 3.6.2中的mule应用程序的特定文件,例如'/opt/applications/app1/log/config/config/log4j2.xml'.常见方法是从存储在资源文件夹中的配置文件log4j2.xml中获取配置,我们需要从其他外部路径读取此配置文件.

推荐答案

默认情况下,mule使用自己的log4j2文件进行登录.要从外部路径读取log4j2.xml配置文件,请在文件应用程序上下文中添加下一个bean,因为该文件指定了在mule上下文中使用的外部文件.

.

应用程序上下文:

     <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>

然后,您需要从文件m子流中导入此上下文,

m子配置

 <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://www.itbaoku.cn/post/1575213.html

问题描述

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.

推荐答案

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>