tags:

views:

131

answers:

2

Hi,

I am trying to group logs of multiple related applications to a single log file.

For example I have 3 applications A1.esb, A2.esb, A3.esb.

I want all the logs from these 3 applications get logged to a single log file called A.log.

Similarly, I want B.log for B1.esb, B2.esb and B3.esb.

I am using log4j in JBoss application server.

I have tried to use TCLFilter but I only succeeded in getting individual applications logging to individual log files. As in, A1.esb logging to A1.log, A2.esb logging to A2.log and so on. But I couldn't figure out a way of grouping these loggings.

A: 

Define an appender you will use for these three logs:

<appender name="A" class="org.jboss.logging.appender.DailyRollingFileAppender">
      <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
      <param name="File" value="${jboss.server.log.dir}/A.log"/>
      <param name="Append" value="true"/>
    <param name="Threshold" value="INFO"/>

      <param name="DatePattern" value="'.'yyyy-MM-dd"/>
      <layout class="org.apache.log4j.PatternLayout">
         <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
      </layout>
   </appender>

Then route your packages to this logger with additivity=false

   <category name="A1.esb" additivity="false">
   <priority value="INFO"/>
      <appender-ref ref="A"/>
   </category>

   <category name="A2.esb" additivity="false">
   <priority value="INFO"/>
      <appender-ref ref="A"/>
   </category>   

   <category name="A3.esb" additivity="false">
   <priority value="INFO"/>
      <appender-ref ref="A"/>
   </category>

I hope you are using different packages for each application.

volothamp
I think the point is that he wants to select the appender based on what application generated the log entry, not which logger name it uses. This is what `TCLFilter` is for, but it doesn't always work.
skaffman
You're right, but maybe he can use his packages as a workaround. If he want to route only his app's log it will work. Obviously it won't work if he want to route all his categories logs in one file.
volothamp
A: 

Thanks a lot guys for your response.

I have managed to fix it by reading some documentation on log4j for jboss.

All I had to do was to specify an appender per application group and inside each appender, I would have a filter chain.

So my log appender shall look like the following.

<appender name="A" class="org.apache.log4j.FileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"></errorHandler>
<param name="Append" value="false"/>
<param name="File" value="${jboss.server.home.dir}/log/A.log"/>
<param name="Threshold" value="INFO"/>

<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
</layout>

<filter class="org.jboss.logging.filter.TCLFilter">
<param name="AcceptOnMatch" value="true"/>
<param name="DeployURL" value="A1.esb"/>
</filter>

<filter class="org.jboss.logging.filter.TCLFilter">
<param name="AcceptOnMatch" value="true"/>
<param name="DeployURL" value="A2.esb"/>
</filter>

<filter class="org.jboss.logging.filter.TCLFilter">
<param name="AcceptOnMatch" value="true"/>
<param name="DeployURL" value="A3.esb"/>
</filter>

<filter class="org.apache.log4j.varia.DenyAllFilter"/>

</appender>

and so on for Group B, which would have B1.esb, B2.esb and B3.esb.