logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mansour <mansour77+li...@ownmail.net>
Subject Re: Logger.getRootLogger() or Logger.getLogger(this.getClass())
Date Tue, 12 Sep 2006 23:40:59 GMT
James:
Thanks alot for your reply. That's exactley what I was missing. Of 
course sub is not a child of logger (as classes) since it was entended 
form Logger.
Now I need just to confirm what I have learnt so far.

public class MainClass{
Logger mainLogger=Logger.getLogger(this.getClass());
BasicConfigurator.configure();
mainLogger.setLevel(Level.ALL);
//.....
//more code
new AnotherClass();
}

class AnotherClass{
//code
Logger subLogger=Logger.getLogger(this.getClass());
BasicConfigurator.configure();
sub.setLevel(Level.ALL);
//more code
}

in this situation,  subLogger is a child of mainLogger. Am I right?? 
that's what I understand. and I need someone to confirm this.
If I am right, then all I have to do is to configure the mainLogger  
(Level, appender, ...etc ) which is I am not worried about at this point.
I just want to know, is that the hierarchy in log4j ??


James Stauffer wrote:

> I think you might be getting the class and logger hierarchies confused.
> sub is not a child of logger (as classes) but the "sub" logger is a
> child (in the logger hierarchy) of the "logger" logger.
>
> On 9/12/06, Mansour <mansour77+lists@ownmail.net> wrote:
>
>> Thanks for helping:
>> Yes, I am using this every time I need a logger, but once in every
>> class. My confussion about hierarchy is I dont know when to use it. Ok
>> Here's what I know:
>> I understand the structure of any tree, and the parent.child notation,
>> but how to create a child logger, and why, and when ??
>> another question: Lets say I have,
>> public class MyMain{
>> //code
>> Logger logger=Logger.getLogger(this.getClass());
>> BasicConfigurator.configure();
>> logger.setLevel(Level.ALL);
>> new SubClass();
>> //more code
>> }
>>
>> public class SubClass{
>> //code
>> Logger sub=Logger.getLogger(this.getClass());
>> BasicConfigurator.configure();
>> sub.setLevel(Level.ALL);
>> //more code
>> }
>>
>> Now in this situation, is sub a child of logger, as logger was created
>> in the parent class ? I dont wanna get into using appenders at this
>> point until I understand the architecture of the package. I would like
>> to understand the hierarchy before going any furthure with log4j.
>> Thank you
>>
>>
>>
>>
>>
>>
>>
>> Blok, Eelke wrote:
>>
>> >Hi again,
>> >
>> >I just realised something else. You say this is the code you're using:
>> >[...]
>> >Logger logger=Logger.getLogger(this.getClass());
>> >BasicConfigurator.configure();
>> >logger.setLevel(Level.ALL);
>> >[...]
>> >
>> >In hindsight, I think my previous message may confuse you where I talk
>> >about attaching multiple appenders and such, because you're only using
>> >the basic configurator and you're not directly dealing with any
>> >appenders (they are an essential part of what makes Log4J so flexible;
>> >be sure to check out the usage of other configurators that let you use
>> >configuration files).
>> >
>> >I think what your problem actually is, is that you're doing this
>> >wherever you want a logger (correct?). You shouldn't. You should
>> >basically only call a configurator once, near the start of your
>> >application. After that, you can request loggers to your heart's 
>> content
>> >and log to them. I'm not sure what the effect of configurating log4j
>> >multiple times will be, but I think you may well end up with multiple
>> >appenders (one for each time you call configure()) attached to your
>> >logger tree, which would explain the multiple log entries.
>> >
>> >Regards,
>> >
>> >Eelke
>> >
>> >
>> >-----Original Message-----
>> >From: Mansour [mailto:mansour77+lists@ownmail.net]
>> >Sent: dinsdag 12 september 2006 9:02
>> >To: Log4J Users List
>> >Subject: Logger.getRootLogger() or Logger.getLogger(this.getClass())
>> >
>> >
>> >Hi there:
>> >I am still new to logging with java. In my project I am using log4j in
>> >each class to trace the excution. However, at some points I'n getting
>> >the logs twice.
>> >I 'll explain what I did. I am using somehting like this in all the
>> >classes :
>> >
>> >Logger logger=Logger.getLogger(this.getClass());
>> >BasicConfigurator.configure();
>> >logger.setLevel(Level.ALL);
>> >//some code ......
>> >logger.info("myMessage");
>> >//more code ....
>> >
>> >when, a method is executed, it logs the message at least 2 times !!!
>> >what's is going on?? by the way, I dont understand the herirachy in the
>> >log4j. I mean what's the difference between Logger.getRootLogger() and
>> >Logger.getLogger(this.getClass()) ??
>> >
>> >
>> >
>> >
>> >
>> >---------------------------------------------------------------------
>> >To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> >For additional commands, e-mail: log4j-user-help@logging.apache.org
>> >
>> >
>> >
>> >PRIVACY: The information transmitted is intended only for the person or
>> >entity to which it is addressed and may contain confidential and/or
>> >priviliged material. Any review, retransmission, dissemination or other
>> >use of this information by persons or entities other than the intended
>> >recipient is prohibited. If you received this in error, please contact
>> >the sender and delete the material from any computer. Thank you.
>> >
>> >
>> >
>> >
>> >---------------------------------------------------------------------
>> >To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> >For additional commands, e-mail: log4j-user-help@logging.apache.org
>> >
>> >
>> >
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>
>>
>
>


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


Mime
View raw message