logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tong123123 <tong123...@yahoo.com.hk>
Subject each log message output twice
Date Thu, 08 Nov 2012 08:49:49 GMT
My log4j.properties file is as follow
log4j.rootLogger=error, A1, A2
log4j.logger.x=info, A1, A2
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout

log4j.appender.A1.layout.ConversionPattern=%d %-5p (%13F:%L) %3x - %m%n

# Appender A2 writes to the file "test".
log4j.appender.A2=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A2.DatePattern='.'yyyy-MM-dd
log4j.appender.A2.File=./debugleveldemo_logs/debugleveldemo.log


# Appender A2 uses the PatternLayout.
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%d %-5p [%t] %-17c{2} (%13F:%L) %3x - %m%n 


in my project, I have a class in package x.y and named TestLog4j.
the relevant code is as follow:
static Logger logger = Logger.getLogger(TestLog4j.class);

void method1(){
        Properties props = new Properties();
        try {
            // the file need placed in C:\workspace\workspace1\TestLog4j {root folder}
            props.load(new FileInputStream("log4j.properties"));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        PropertyConfigurator.configure(props);
        logger.debug("debug");
        logger.info("info");
        logger.warn("warn");
        System.out.println("see system out");
    }

the output log message is duplicate as follow:
2012-11-08 16:37:10,478 INFO  (TestLog4j.java:30)     - info
2012-11-08 16:37:10,478 INFO  (TestLog4j.java:30)     - info
2012-11-08 16:37:10,490 WARN  (TestLog4j.java:31)     - warn
2012-11-08 16:37:10,490 WARN  (TestLog4j.java:31)     - warn
see system out

why each log message is displayed twice? for rootLogger, the level is error, so should not
be triggered, and only log4j.logger.x is triggered, so I expected the debug message should
be displayed only once.
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message