Interview Questions

How to configure Log4j for a Web application in JBoss?

To configure Log4j for a Web application in Jboss, perform the following.

1. Remove any log4j.properties file from your Web application.

2. Remove log4j.jar, common-logging.jar files from WEB-INF/lib directory in your Web application.

3. Add the following appender to /server/default/conf/jboss-log4j.xml

<appender name="TDD" class="org.jboss.logging.appender.RollingFileAppender">
       <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
       <param name="File" value="${jboss.server.log.dir}/TDD.log"/>
       <param name="Append" value="true"/>
       <param name="MaxFileSize" value="1024KB"/>
       <param name="MaxBackupIndex" value="2"/>

       <layout class="org.apache.log4j.PatternLayout">
          <param name="ConversionPattern" value="[TDD ] %d{ISO8601} %p %c{1} | %m%n"/>
        </layout>
</appender>


<category name="in.tdd" >
         <priority value="DEBUG" />
         <appender-ref ref="TDD"/>
</category>

You can configure all the Log4j related properties using the <appender> and <category> tags.