Solved

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

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
even odd program using while loop 3 60
jdbc error in jsp application 20 64
ejb entity bean example 2 17
Is Applet the way to go for my drag and drop system? 8 25
This article will show, step by step, how to integrate R code into a R Sweave document
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 …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

830 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