Log4j en JBoss AS 7

Para utilizar una configuración de logj4 personalizada desde la propia aplicación, necesitaremos incluir el fichero log4j.xml.

/WEB-INF/classes/log4j.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
  <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
   <appender name="R" class="org.apache.log4j.RollingFileAppender">
    <param name="File" value="${jboss.server.log.dir}/myapp.log" />
    <param name="Append" value="true"/>
    <param name="MaxFileSize" value="1MB" />
    <param name="MaxBackupIndex" value="5" />
    <layout class="org.apache.log4j.PatternLayout">
     <param name="ConversionPattern" value="%d{dd/MM/yyyy hh:mm:ss} %-5p [%c] %m%n"/>
   </layout>
  </appender>
  <!-- The "category" represents the package names of your Application APIs which we want to log -->
  <category name="com.myapp">
   <priority value="INFO" />
   <appender-ref ref="R" />
  </category>
  <root>
   <priority value="INFO" />
   <appender-ref ref="R"/>
  </root>
 </log4j:configuration>

Además es necesario que nuestro .war contenga la libreria WEB-INF/lib/log4j-1.2.16.jar

pom.xml

<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <version>1.2.16</version>
</dependency>

Así como indicar explicitamente a JBoss, que no utilize su propia libreria y configuración mediante este fichero:
/META-INF/jboss-deployment-structure.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
  <deployment>
    <exclusions>
        <module name="org.apache.log4j" />
    </exclusions>
  </deployment>
</jboss-deployment-structure>

Documentación
* http://middlewaremagic.com/jboss/?p=1458

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s