You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Carl Dreher <cd...@sta.samsung.com> on 2004/11/30 23:16:32 UTC

Beginner questions

I've been trying to figure out Log4J, and have read the "documentation"
multiple times.  Still have lots of questions.  Maybe someone can shed
some light.

 

1.	What is "rootLogger" in the properties file?  Is that a reserved
keyword?  The JavaDoc shows a RootLogger class, but not rootLogger. 

 

2.	Here is a code snippet: 

Logger logger = Logger.getLogger("ABC");

logger.warn("This is a warning.");

 

As I understand it, this code looks up a Logger that was defined in the
properties file, such as

 

log4j.logger.ABC=debug

 

            and then writes "This is a warning" it to the appropriate
place.  True?  If so, then how does this code from the examples work?

 

                        Logger logger =
Logger.getLogger(this.class.getName() );

 

            Won't this fail unless there is an entry in the properties
file for EVERY class that attempts to log information?  If it can't find
a named logger, what does it default to?

 

3.	Is the "rootLogger" statement in the properties file optional?
EVERY example shows it.  Is it OK just to have 

 

log4j.logger.ABC=debug

log4j.logger.DEF=debug

 

            with no "rootLogger" statement?

 

4.	Is the appender required to have the same name as the logger?
For example, it is ok to have: 

 

log4j.logger.ABC=debug, XYZ

log4j.appender.XYZ=org.apache.log4j.DailyRollingFileAppender

 

Of course, the biggest question is, "Why is the documentation so weak?"
(Hint to tech writers and documenters:  If you are describing something
and find yourself writing "...in other words...", STOP!  That phrase
merely acknowledges that your first words weren't worth keeping and
you're too lazy to rewrite them.)  And speaking of documentation, what's
up with the Log4J Version 1.2.9 download?  The 'examples' folder is full
of completely empty subfolders.

 

-        Carl Dreher

 

 

 


Re: Beginner questions

Posted by Paul Smith <ps...@aconex.com>.
Logger.getLogger("Foo") creates a new instance of the Logger for "Foo" 
if it has not already been created, regardless of what has been 
specified in the configuration file, and sets up the default level for 
this new Logger to be "nothing", which means it's inherits the level 
from it's parent, or it's parent's parent, etc until at least one of the 
ancestor's has an explicit level set.  In this way each Logger always 
has an "effective" Level, which is the first level defined going up the 
logger hierarchy.

That's where the Root logger comes in, it's always there, even if not 
specified in the configuration file, and has a default Level of DEBUG, 
so even if you do not have a configuration file at all, all Loggers 
would have an effective level, even if they have nothing explicitly defined.

That's why

Logger logger =
Logger.getLogger(this.class.getName() );

works, because it gets created if it's not been asked for before.

Of course without a configuration file (or done programmitically), 
you'll never "see" any logging statements outputted anwhere because 
Loggers by themselves don't output anything, they use one or more Appenders.

I'd recommend Ceki's book: http://www.qos.ch/shop/products/eclm/

cheers,

Paul

Carl Dreher wrote:

>I've been trying to figure out Log4J, and have read the "documentation"
>multiple times.  Still have lots of questions.  Maybe someone can shed
>some light.
>
> 
>
>1.	What is "rootLogger" in the properties file?  Is that a reserved
>keyword?  The JavaDoc shows a RootLogger class, but not rootLogger. 
>
> 
>
>2.	Here is a code snippet: 
>
>Logger logger = Logger.getLogger("ABC");
>
>logger.warn("This is a warning.");
>
> 
>
>As I understand it, this code looks up a Logger that was defined in the
>properties file, such as
>
> 
>
>log4j.logger.ABC=debug
>
> 
>
>            and then writes "This is a warning" it to the appropriate
>place.  True?  If so, then how does this code from the examples work?
>
> 
>
>                        Logger logger =
>Logger.getLogger(this.class.getName() );
>
> 
>
>            Won't this fail unless there is an entry in the properties
>file for EVERY class that attempts to log information?  If it can't find
>a named logger, what does it default to?
>
> 
>
>3.	Is the "rootLogger" statement in the properties file optional?
>EVERY example shows it.  Is it OK just to have 
>
> 
>
>log4j.logger.ABC=debug
>
>log4j.logger.DEF=debug
>
> 
>
>            with no "rootLogger" statement?
>
> 
>
>4.	Is the appender required to have the same name as the logger?
>For example, it is ok to have: 
>
> 
>
>log4j.logger.ABC=debug, XYZ
>
>log4j.appender.XYZ=org.apache.log4j.DailyRollingFileAppender
>
> 
>
>Of course, the biggest question is, "Why is the documentation so weak?"
>(Hint to tech writers and documenters:  If you are describing something
>and find yourself writing "...in other words...", STOP!  That phrase
>merely acknowledges that your first words weren't worth keeping and
>you're too lazy to rewrite them.)  And speaking of documentation, what's
>up with the Log4J Version 1.2.9 download?  The 'examples' folder is full
>of completely empty subfolders.
>
> 
>
>-        Carl Dreher
>
> 
>
> 
>
> 
>
>
>  
>

-- 

*Paul Smith
*Software Architect

	

*Aconex
* 31 Drummond Street, Carlton, VIC 3053, Australia
*Tel: +61 3 9661 0200  *Fax: +61 3 9654 9946
Email: psmith@aconex.com  www.aconex.com**

This email and any attachments are intended solely for the addressee. 
The contents may be privileged, confidential and/or subject to copyright 
or other applicable law. No confidentiality or privilege is lost by an 
erroneous transmission. If you have received this e-mail in error, 
please let us know by reply e-mail and delete or destroy this mail and 
all copies. If you are not the intended recipient of this message you 
must not disseminate, copy or take any action in reliance on it. The 
sender takes no responsibility for the effect of this message upon the 
recipient's computer system.**


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org