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:[EMAIL PROTECTED] 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to