Solved

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

Posted on 2011-02-11
4
438 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
String array comparison 4 57
Java program running SQL query 5 62
American Express @Work site and Java 4 95
convert Absolute path to relative path of FTP location 7 50
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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 viewer will learn how to implement Singleton Design Pattern in Java.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

734 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