我需要在wildfly-domain中的服务器组上部署多个war文件。当我只部署一个应用程序时,配置完全正常,并按预期生成日志。但是,在部署第二个war文件后,部署1和部署2的所有日志都将写入第二个部署的日志文件。它似乎是每个部署日志记录中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>
答案 0 :(得分:2)
每部署日志记录基于日志上下文工作。由于您在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.jmx
,org.jboss.msc
,org.wildfly.clustering.singleton
,org.jboss.as.server
或org.wildfly.clusttering.server
。