Wildfly 8 日志记录 - 多个部署的每个部署配置不起作用

Wildfly 8 Logging- Per deployment config for multiple deployments not working

我需要在 wildfly 域中的服务器组上部署多个 war 文件。当我只部署一个应用程序时,配置工作得很好并且日志按预期生成。但是,在部署第二个 war 文件后,部署一和部署二的所有日志都会写入第二个部署的日志文件。这似乎是每个部署日志记录中 wildfly 的一个错误。有什么建议吗?

我在log4j.xml里面配置了RollingFileAppender。

日志配置:App1

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
<log4j:configuration>
<appender name="logFile" class="org.apache.log4j.RollingFileAppender">
    <param name="File" value="${jboss.server.log.dir}/deploy1.log" />
    <param name="Append" value="true" />
    <param name="Threshold" value="TRACE" />
    <param name="MaxFileSize" value="25MB" />
    <param name="MaxBackupIndex" value="30" />
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" 
            value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
    </layout>
</appender>
<logger name="com.akash.deploy1">
    <level value="DEBUG" />
</logger>
<root>
    <level value="INFO" />
    <appender-ref ref="logFile" />
</root>
</log4j:configuration>

日志配置:App2

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
<log4j:configuration>
    <appender name="logFile" class="org.apache.log4j.RollingFileAppender">
        <param name="File" value="${jboss.server.log.dir}/deploy2.log" />
        <param name="Append" value="true" />
        <param name="Threshold" value="TRACE" />
        <param name="MaxFileSize" value="25MB" />
        <param name="MaxBackupIndex" value="30" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" 
                value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
        </layout>
    </appender>
    <logger name="com.akash.deploy2">
        <level value="DEBUG" />
    </logger>
    <root>
        <level value="INFO" />
        <appender-ref ref="logFile" />
    </root>
</log4j:configuration>

域配置

<add-logging-api-dependencies value="false"/>

jboss-部署结构

    <jboss-deployment-structure>
    <deployment>
        <exclusions>
            <!-- Exclude container version of hibernate. By default its version 4, we want
                bundled version 3 loaded -->
            <module name="org.hibernate" slot="main" />
            <module name="org.hibernate.validator" />
            <module name="org.hibernate.validator.cdi" slot="main" />
        </exclusions>
        <dependencies>
            <module name="org.apache.commons.logging" />
            <module name="org.apache.commons.collections" />
            <module name="org.dom4j" />
            <module name="org.apache.log4j" />
            <module name="org.slf4j" />
            <module name="org.apache.camel" />
            <module name="org.springframework" />
            <module name="org.hibernate" slot="3.6.10" />
            <module name="net.sf.ehcache" />
            <module name="org.jboss.as.jmx" />
            <module name="org.apache.xerces" />
            <module name="asm.asm" />
            <module name="org.jboss.msc" />
            <module name="org.wildfly.clustering.singleton" />
            <module name="org.jboss.as.server" />
            <module name="com.oracle.ojdbc7" />
            <module name="org.wildfly.clustering.server"/>
        </dependencies>
        <exclude-subsystems>
            <subsystem name="logging" />
        </exclude-subsystems>
    </deployment>
</jboss-deployment-structure>

每个部署的日志记录基于日志上下文工作。由于您在 jboss-deployment-structure.xml 中排除了日志记录子系统,因此两个部署都使用相同的日志上下文。

要使其按预期工作,您需要将 add-logging-api-dependencies 设置回 true。在 CLI 中:

/profile=default/subsystem=logging:write-attribute(name=add-logging-api-dependencies, value=true)

然后在您的 jboss-deployment-structure.xml 中删除对日志子系统的排除。您还可以删除 3 个日志记录包含,因为它们会自动添加。

<jboss-deployment-structure>
    <deployment>
        <exclusions>
            <!-- Exclude container version of hibernate. By default its version 4, we want
                bundled version 3 loaded -->
            <module name="org.hibernate" slot="main" />
            <module name="org.hibernate.validator" />
            <module name="org.hibernate.validator.cdi" slot="main" />
        </exclusions>
        <dependencies>
            <module name="org.apache.commons.collections" />
            <module name="org.dom4j" />
            <module name="org.apache.camel" />
            <module name="org.springframework" />
            <module name="org.hibernate" slot="3.6.10" />
            <module name="net.sf.ehcache" />
            <module name="org.jboss.as.jmx" />
            <module name="org.apache.xerces" />
            <module name="asm.asm" />
            <module name="org.jboss.msc" />
            <module name="org.wildfly.clustering.singleton" />
            <module name="org.jboss.as.server" />
            <module name="com.oracle.ojdbc7" />
            <module name="org.wildfly.clustering.server"/>
        </dependencies>
    </deployment>
</jboss-deployment-structure>

其中一些模块依赖项看起来也有点可疑。我不确定您为什么需要 org.jboss.as.jmxorg.jboss.mscorg.wildfly.clustering.singletonorg.jboss.as.serverorg.wildfly.clusttering.server.