1 Reply Latest reply: Dec 22, 2010 11:11 PM by 826156 RSS

    log4j : How to avoid duplicate logmessages in a multithreaded application?

    843798
      Hi,
      I m using log4j for my heavily multithreaded JAVA application. After my application comes up, a few minutes later , I find many duplicate logger messages on the console(only logger messages in threads are being displayed 8-9 times each). Is it that my application being multithreaded or is there something wrong with my configuration file?

      My log4j-config.xml is as below:-
      <?xml version="1.0" encoding="UTF-8"?> 
      <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
      
      <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
                           configDebug="true">
      
           <appender name="ASYNC" class="org.apache.log4j.AsyncAppender" additivity="false">
                   <appender-ref ref="TEMP"/>
                <appender-ref ref="CONSOLE"/>
                <appender-ref ref="TRACE"/>
                <appender-ref ref="DEBUG"/>
                <appender-ref ref="INFO"/>
                <appender-ref ref="WARN"/>
                <appender-ref ref="ERROR"/>
                <appender-ref ref="FATAL"/>
           </appender>
      
           <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
                <!-- param name="ImmediateFlush" value="true"/-->
                <layout class="org.apache.log4j.PatternLayout">
                       <!-- param name="ConversionPattern" 
                                  value="%d %-5p [%t] %C %A (%F:%L) - %m%n"/-->
                </layout>
           </appender>
      
      
           <appender name="TEMP" class="org.apache.log4j.FileAppender">
                <param name="File" value="/var/log/abs/acpu_fun/acpu.log"/>
                <layout class="org.apache.log4j.PatternLayout">
                       <param name="ConversionPattern" 
                                  value="%d %-5p [%t] %C (%F:%L) - %m%n"/>
                </layout>
           </appender>
           
            <appender name="TRACE" class="org.apache.log4j.FileAppender">
           <param name="File" value="/var/log/abs/acpu_fun/acputrc.log"/>
           <param name="Threshold" value="TRACE"/>
           <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" 
                                 value="%d %-5p [%t] %C (%F:%L) - %m%n"/>
                </layout>
           </appender>
      
            <appender name="DEBUG" class="org.apache.log4j.FileAppender">
           <param name="File" value="/var/log/abs/acpu_fun/acpudeb.log"/>
           <param name="Threshold" value="DEBUG"/>
           <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" 
                                 value="%d %-5p [%t] %C (%F:%L) - %m%n"/>
                </layout>
           </appender>
      
           <appender name="INFO" class="org.apache.log4j.FileAppender">
           <param name="File" value="/var/log/abs/acpu_fun/acpuinfo.log"/>
           <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" 
                                 value="%d %-5p [%t] %C (%F:%L) - %m%n"/>
                </layout>
           
                <filter class="org.apache.log4j.varia.LevelMatchFilter">
                            <param name="LevelToMatch" value="info"/>
                    </filter>
      
           <filter class="org.apache.log4j.varia.DenyAllFilter"/>     
           </appender>
      
           <appender name="WARN" class="org.apache.log4j.FileAppender">
           <param name="File" value="/var/log/abs/acpu_fun/acpuwar.log"/>
           <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" 
                                 value="%d %-5p [%t] %C (%F:%L) - %m%n"/>
                </layout>
           
                <filter class="org.apache.log4j.varia.LevelMatchFilter">
                       <param name="LevelToMatch" value="warn"/>
                  </filter>
           <filter class="org.apache.log4j.varia.DenyAllFilter"/>     
           </appender>
      
           <appender name="ERROR" class="org.apache.log4j.FileAppender">
           <param name="File" value="/var/log/abs/acpu_fun/acpuerr.log"/>
           <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" 
                                 value="%d %-5p [%t] %C (%F:%L) - %m%n"/>
                </layout>
           
                <filter class="org.apache.log4j.varia.LevelMatchFilter">
                       <param name="LevelToMatch" value="error"/>
                  </filter>
           <filter class="org.apache.log4j.varia.DenyAllFilter"/>     
           </appender>
      
           <appender name="FATAL" class="org.apache.log4j.FileAppender">
           <param name="File" value="/var/log/abs/acpu_fun/acpufatl.log"/>
           <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" 
                                 value="%d %-5p [%t] %C (%F:%L) - %m%n"/>
                </layout>
           
                <filter class="org.apache.log4j.varia.LevelMatchFilter">
                       <param name="LevelToMatch" value="fatal"/>
                  </filter>
           <filter class="org.apache.log4j.varia.DenyAllFilter"/>     
           </appender>
      
           <appender name="SLCS" class="org.apache.log4j.FileAppender">
                <param name="File" value="/var/log/slcs/slcs.log"/>
                <layout class="org.apache.log4j.PatternLayout">
                       <param name="ConversionPattern" 
                                  value="%d %-5p [%t] %C (%F:%L) - %m%n"/>
                </layout>
           </appender>
      
           <category name="com.aircell.abs.acpu.softwareloadconfig" additivity="false">
            <level value="debug"/>
           <appender-ref ref="SLCS"/>
            </category>
           
           <root>
                <priority value="info"/>
                <appender-ref ref="ASYNC"/>
           </root>
      </log4j:configuration>
      Regards.