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 "Klein, Scott @ TW" <sc...@L-3com.com> on 2002/06/19 18:42:40 UTC

How do you handle Logger hierarchy?

I am about to go back and retrofit (a lot of) code with Log4J, but I was
looking for some input on how each class should retrieve its Logger.

At first, I wanted each class to:

Logger logger = Logger.getLogger( this.getClass() );

but now I am concerned that I am going to have 10's if not 100's of Logger
instances sitting on my machine - which do not necessarily have a different
configuration than the root logger. 

The second simple option is to have them all do:

Logger logger = Logger.getRootLogger();

but now there is no flexibility in the logging configuration on a class
basis.

Finally, perhaps a trade off is:

Logger logger;
if( (logger=Logger.exists(this.getClass()) == null )
	logger = Logger.getRootLogger();

but this means you can't make use of the hierarchical context of the loggers
and packages - where com.foo.Bar and com.foo.FooBar will use the
configuration defined for com.foo.

Am I missing an option here, or do I just have to suck it up and make a
decision?


thanks
scott


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: How do you handle Logger hierarchy?

Posted by "Michael A. McAngus" <ma...@infinet.com>.
See, I told you someone would correct me.

I wasn't digging into Logger and Category, it was just a tangential 
observation which was evidently wrong.

BTW, I didn't think I was reporting a bug.  On the contrary, I thought 
it would be a good thing if new Loggers were instantiated only when they 
were specified in the configuration, and any call to get a Logger simply 
searched up the Hierarchy until it found one, and then used that one.

Still, I'm sorry I muddied the waters with my mis-interpretations.

-- 
Cheers,
Mike McAngus
mam@infinet.com

Ceki Gülcü wrote:

>
> Loger.getLogger(Class x) will always return the logger named
> x.getName(). If you observe anything else it's a bug. If you
> send a bug report reproducing this bug, the beer is on me. Asking you
> to reciprocate would be unfair. :-)
>
> At 23:03 19.06.2002 -0400, you wrote:
>
>> From some of my debugging sessions, it appears that 
>> Logger.getLogger(Class) will get the logger nearest the root that 
>> matches the FQCN.  In many of my debugging sessions, I only specified 
>> the root logger, and I got it for all of my Logger calls.
>>
>> I'm sure someone will correct me if I've mis-interpreted what I saw. :^)
>>
>> -
>> Cheers,
>> Mike McAngus
>> mam@infinet.com
>
>
> -- 
> Ceki
>
>
> -- 
> To unsubscribe, e-mail:   
> <ma...@jakarta.apache.org>
> For additional commands, e-mail: 
> <ma...@jakarta.apache.org>
>
>
>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: How do you handle Logger hierarchy?

Posted by Ceki Gülcü <ce...@qos.ch>.
Loger.getLogger(Class x) will always return the logger named
x.getName(). If you observe anything else it's a bug. If you
send a bug report reproducing this bug, the beer is on me. Asking you
to reciprocate would be unfair. :-)

At 23:03 19.06.2002 -0400, you wrote:
> From some of my debugging sessions, it appears that 
> Logger.getLogger(Class) will get the logger nearest the root that matches 
> the FQCN.  In many of my debugging sessions, I only specified the root 
> logger, and I got it for all of my Logger calls.
>
>I'm sure someone will correct me if I've mis-interpreted what I saw. :^)
>
>-
>Cheers,
>Mike McAngus
>mam@infinet.com

--
Ceki


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: How do you handle Logger hierarchy?

Posted by "Michael A. McAngus" <ma...@infinet.com>.
 From some of my debugging sessions, it appears that 
Logger.getLogger(Class) will get the logger nearest the root that 
matches the FQCN.  In many of my debugging sessions, I only specified 
the root logger, and I got it for all of my Logger calls.

I'm sure someone will correct me if I've mis-interpreted what I saw. :^)

-
Cheers,
Mike McAngus
mam@infinet.com

Klein, Scott @ TW wrote:

>I am about to go back and retrofit (a lot of) code with Log4J, but I was
>looking for some input on how each class should retrieve its Logger.
>
>At first, I wanted each class to:
>
>Logger logger = Logger.getLogger( this.getClass() );
>
>but now I am concerned that I am going to have 10's if not 100's of Logger
>instances sitting on my machine - which do not necessarily have a different
>configuration than the root logger. 
>
>The second simple option is to have them all do:
>
>Logger logger = Logger.getRootLogger();
>
>but now there is no flexibility in the logging configuration on a class
>basis.
>
>Finally, perhaps a trade off is:
>
>Logger logger;
>if( (logger=Logger.exists(this.getClass()) == null )
>	logger = Logger.getRootLogger();
>
>but this means you can't make use of the hierarchical context of the loggers
>and packages - where com.foo.Bar and com.foo.FooBar will use the
>configuration defined for com.foo.
>
>Am I missing an option here, or do I just have to suck it up and make a
>decision?
>
>
>thanks
>scott
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>
>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>