Solved

Log4j : Does any know why only Fatal messages being logged when logger is set to DEBUG

Posted on 2011-02-11
4
432 Views
Last Modified: 2012-08-13
Does any know why only Fatal messages are being logged when I have the logger is set to DEBUG :

log4j.logger.TimeEntry=DEBUG, stdout, TimeEntry

## Appenders defined.
##
## This appender writes to the console.
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{MM/dd/yy HH:mm:ss.SSS} [%C{1}:%L] %-5p - %m%n
##
##
## This appender writes to the timeEntry.log file.
log4j.appender.TimeEntry=org.apache.log4j.RollingFileAppender
log4j.appender.TimeEntry.File=c:\\TimeEntry\\logs\\TimeEntryClient.log
log4j.appender.TimeEntry.MaxFileSize=50KB
log4j.appender.TimeEntry.MaxBackupIndex=10
log4j.appender.TimeEntry.ImmediateFlush=true
log4j.appender.TimeEntry.layout=org.apache.log4j.PatternLayout
log4j.appender.TimeEntry.layout.ConversionPattern=%d{MM/dd/yy HH:mm:ss} [%C{1}:%L] %-5p - %m%n

public class TimeEntryLogger {
  public static Logger TELog ;
  private static TimeEntryLogger instance ;

  private TimeEntryLogger(String file) {      

    TELog = Logger.getLogger("TimeEntry") ;
    Properties logProps = new Properties();
    try {      
       logProps.load(new FileInputStream(file));
       PropertyConfigurator.configure(logProps);
    }                  
   catch(IOException e) {
        throw new RuntimeException("Unable to load logging property " + file);
    }
}

This works
TimeEntryLogger.TELog.fatal("fatal message");

This does not work
TimeEntryLogger.TELog.debug("debug message");
0
Comment
Question by:johnth1957
4 Comments
 
LVL 5

Expert Comment

by:jaiminpsoni
ID: 34874407
remove the line and put it like this...
<<<< log4j.logger.TimeEntry=DEBUG, stdout, TimeEntry

>>>> log4j.rootLogger=DEBUG, stdout

If this works then the issue is with that line...
0
 

Author Comment

by:johnth1957
ID: 34874494
Did not work either with stdout or TimeEntry
0
 
LVL 7

Accepted Solution

by:
garypfirstech earned 500 total points
ID: 34875602
The static iniitializer of the Logger class is initializing Log4J according to the default initialization rules and is probably not using your properties file.  Either call PropertyConfigurator.resetConfiguration() immediately before calling PropertyConfigurator.configure(logProps) or move the Logger.getLogger(..) call to after your try/catch block.  To see exactly what's happening during configuration, set system property log4j.debug (it need not have a value).

See the javadoc at http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PropertyConfigurator.html#doConfigure%28java.lang.String,%20org.apache.log4j.spi.LoggerRepository%29 for more information.
0
 
LVL 92

Expert Comment

by:objects
ID: 34875679
>        PropertyConfigurator.configure(logProps);

why are you doing this? You have already created your Logger at this point
Just put log4.properties in your classpath and it will get loaded automatically
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now