本文介绍了file子3.6.2中2子应用程序的文件中的log4j2.xml配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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文件进行日志记录.要从外部路径读取log4j2.xml配置文件,请在文件应用程序上下文"中添加下一个bean,为此,请指定要在"Mule常规"上下文中使用的外部文件.

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.

应用上下文:

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

然后,您需要使用以下命令从文件Mule流中导入此上下文:

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

Mule Config

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> 

这篇关于file子3.6.2中2子应用程序的文件中的log4j2.xml配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 04:31