Using RootLogger for all Classes
1 posts in topic
Flat View  Flat View

Posted By:   Ludwma_Ludwma
Posted On:   Wednesday, July 30, 2003 04:03 AM


a simple question.

Why should I instance a different Logger for every class of my project? Could I use only the RootLogger? Or are there any performance problem if I use only the RootLogger for all my classes?

Thank You



Re: Using RootLogger for all Classes

Posted By:   Ivo_Limmen  
Posted On:   Wednesday, July 30, 2003 05:31 AM

If you use the Logger.getLogger(getclass()) you will create a new logger for each class. This does not mean that you will create files for each class. If you configure only the rootlogger in the properties to log to a file, all classes will log to that file. But by using this technique you can change the output of one specific class later on. You can start by configurating log4j like this:

log4j.rootLogger=DEBUG, consoleLog

(Where consoleLog is a console appender). Later when you have a class you need to debug you can change the properties to:

log4j.rootLogger=INFO, consoleLog

# My error clas
log4j.logger.com.company.product.ClassName=DEBUG, myFileLog

No all INFO and up messages from all the other classes will go to the console, but all DEBUG messages (and up) from the class 'com.company.product.ClassName' will be send to the myFileLog appender.
For more information look at the website of log4j.
About | Sitemap | Contact