配置Jboss eap 6.2以使用log4j2

时间:2014-08-14 03:49:04

标签: java-ee jboss log4j jboss6.x log4j2

您好我开发了多模块j2ee ear部署,我需要更改它的日志配置以使用log4j2。

部署包不包含任何log4j配置,它使用jboss默认本机日志记录,我需要做的是将jboss本机日志记录更改为log4j2。到目前为止,我找到了一种方法,即在每个模块和log4j配置文件中包含log4j2库。但是这种方法似乎很成问题,因为如果需要更改日志记录级别,我将不得不部署整个应用程序来更改所有log4j配置文件。

我的问题是,他们是否可以更改Jboss(不在我的应用程序中)的配置以使用log4j2进行日志记录?

3 个答案:

答案 0 :(得分:1)

我正在寻找这个问题的答案,这就是我发现的。

如果您希望使用JBoss的日志记录系统(在standalone.xml文件中定义日志记录),不能从JBoss EAP 6.3(JBoss 7)开始使用Log4j2。 JBoss目前只支持log4j 1.2.X。

此外,您不能在您的网络应用程序中包含log4j JAR。 JBoss会自动为log4J 1.2,SLF4J,common-logging和java.util.logging注入API,但前提是不包含在应用程序中。希望这有助于其他人。

最后注意:我找不到Log4j2-> Log4j桥接器或其他机制。

答案 1 :(得分:1)

您可以将以下内容添加到jboss-deployment-structure.xml(包含在战争中)

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
   <deployment>
      <!-- 
      Prevent that the server add automatically dependencies -->
      <!-- Exclude all logging dependencies so we can use log4j2 -->
      <exclusions>
         <module name="org.apache.commons.logging" />
         <module name="org.apache.log4j" />
         <module name="org.jboss.logging" />
         <module name="org.jboss.logging.jul-to-slf4j-stub" />
         <module name="org.jboss.logmanager" />
         <module name="org.jboss.logmanager.log4j" />
         <module name="org.slf4j" />
         <module name="org.slf4j.impl" />
      </exclusions>  
   </deployment>
</jboss-deployment-structure>

然后,您可以在应用程序中包含log4j2 jar,并在添加apprpriate模块定义时将log4j2配置文件放在文件系统文件夹中。

这完全取决于您的应用程序正在使用的日志记录API - 例如针对哪个api进行编译。如果你可以改变它,我建议使用slf4j,这将是最灵活的解决方案。

答案 2 :(得分:-1)

The Log4J configuration file is located at server/xxx/conf/jboss-log4j.xml in jboss.

If you use Log4J or Apache Jakarta Commons Logging within your application, you can log your application by adding category entries to the jboss-log4j.xml file. For example, if your application uses the package name org.jbia, you can log the classes in that package and its subpackages by adding a category to the jboss-log4j.xml file, as shown below :

<log4j:...>
<category name="org.jbia">
<priority value="DEBUG"/>
</category>
</log4j>