Solved

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

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Application launch issue with Apache Tomcat 5 45
Java Options in Zimbra Server 2 54
fibonacci ten numbers 4 39
servlet example 17 32
This article will show, step by step, how to integrate R code into a R Sweave document
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

777 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