You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by "Harp, George" <GH...@GAINSystems.com> on 2005/08/10 19:07:13 UTC

Duplicate logging messages

Hello I am using log4j.1.2.9.jar and when I use the category element I get
duplicate log messages.
I am enclosing the code and a log4j.xml that works and the one that
duplicates the log messages.
Can you please  tell me what I am messing up?

I need to be able to set the default logging level for a appender and then
designate selected classes to have a different log level.

Help?


MyTest.java:
import org.apache.log4j.Logger;

public class MyTest
{
   private static Logger logger_m =
      Logger.getLogger( MyTest.class );
   
   public static void main( String[ ] args )
   {
      logger_m.info( "Began" );
      logger_m.info( "Ended" );
   }

}


log4j.xml that does not duplicate log messages:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<!-- Make debug="true" attribute for parsing information -->
<log4j:configuration debug="null"
xmlns:log4j="http://jakarta.apache.org/log4j/">
    
    <appender name="BatchLogFile" 
              class="org.apache.log4j.FileAppender">
        <param name="File"
               value="${user.dir}/BatchLogFile.log"/>
   
        <param name="Threshold"
               value="INFO"/>      
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern"
                   value="%d{dd-MM-yyyy HH:mm:ss} %-9.9p %-19.19C{1}
%-19.19M %m%n"/>
        </layout>
    </appender>
    
   
    
    <root>
        <appender-ref ref="BatchLogFile"/>
    </root>
</log4j:configuration>



logj4.xml that duplicates log messages:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<!-- Make debug="true" attribute for parsing information -->
<log4j:configuration debug="null"
xmlns:log4j="http://jakarta.apache.org/log4j/">
    
    <appender name="BatchLogFile" 
              class="org.apache.log4j.FileAppender">
        <param name="File"
               value="${user.dir}/BatchLogFile.log"/>
         
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern"
                   value="%d{dd-MM-yyyy HH:mm:ss} %-9.9p %-19.19C{1}
%-19.19M %m%n"/>
        </layout>
    </appender>
    
    <category name="MyTest">
       <priority value="INFO" />
       <appender-ref ref="BatchLogFile"/>
    </category>
    
    <root>
        <appender-ref ref="BatchLogFile"/>
    </root>
</log4j:configuration>

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org