1

We have a bunch of projects that get deployed in the same Jboss app. server. Each project has its own log4j.properties in its WEB-INF directory.

The idea is for each project to have its own logfile into which it writes its logs.

Any ideas on how this can be achieved.

user1717230
  • 443
  • 1
  • 15
  • 30
  • which version of jboss you are using ? – gYanI Feb 13 '13 at 07:06
  • if you are using jboss 7.x then you can try this http://stackoverflow.com/questions/14182257/using-applications-log4j-configuration-under-jboss-7-1-1/14337990#14337990 – gYanI Feb 13 '13 at 07:07

1 Answers1

0

First of all you don't mention the JBoss version you're using. You've to take in mind that JBoss versions prior to AS7 include its own log4j version (libraries and configuration file: conf/jboss-log4j.xml), so by default JBoss will ignore the log4j.properties file you've in each of your projects.

That said, you have two approaches to configure a log file for each application:

  1. Centralized way: configure it in Jboss, through the conf/jboss-log4j.xml. This way you won't need to modify your applications, or
  2. Modify your applications so that they take their own log4j libraries (you'll have to include them in the ear/war), not the Jboss ones.

For the first approach you'll have to define an appender for each of your applications, and then categories for the application packages, in the conf/jboss-log4j.xml file. For example, to configure a log file for an application called app1.war which classes are in a package called com.foo.app1, you'd have to add:

   <appender name="APP1_APPENDER" class="org.jboss.logging.appender.DailyRollingFileAppender">
      <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
      <param name="File" value="${jboss.server.log.dir}/app1.log"/>
      <param name="Append" value="true"/>
      <!-- Rollover at midnight each day -->
      <param name="DatePattern" value="'.'yyyy-MM-dd"/>    
      <layout class="org.apache.log4j.PatternLayout">
         <!-- The default pattern: Date Priority [Category] (Thread) Message\n -->
         <param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n"/>
      </layout>
   </appender>
   ...
   ...
   <category name="com.foo.app1" additivity="true">
      <priority value="INFO"/>
      <appender-ref ref="APP1_APPENDER"/>
   </category>

You'll have to add a customized set of blocks like this one for each project you want to define a log file for, respectively.

If you prefer the second approach, as said you'll have to include the log4j libraries in each project and isolate each application so that it takes the libraries included in the application not the ones from JBoss. Look at section 10.3.7 of the Jboss logging file for more information about this approach.

Toni
  • 1,381
  • 10
  • 16
  • thanks for the answer toni. I have tried the second approach and got stuck at the point where I need to log the dependency class which is being used by multiple projects. http://stackoverflow.com/questions/14858615/cross-logging-issue-for-2-projects-using-same-dependency – user1717230 Feb 14 '13 at 14:20