Solved

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

Posted on 2011-02-11
4
429 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

759 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

21 Experts available now in Live!

Get 1:1 Help Now