If you use a lot of inheritance, declaring your loggers in the private
static final way will make calls to logging that are in inherited code
to appear as coming from the superclass.
For example:
class ExampleA {
private static final Logger logger_m = Logger.getLogger(ExampleA.class);
void hello() {
logger_m.info("Hello!");
}
}
class ExampleB extends ExampleA {
private static final Logger logger_m = Logger.getLogger(ExampleB.class);
void hi() {
logger_m.info("This is a greeting:");
hello();
logger_m.info("How are you?");
}
}
The output from hi() would be like:
[INFO] (ExampleB): This is a greeting:
[INFO] (ExampleA): Hello!
[INFO] (ExampleB): How are you?
If you have multiple classes sublclassing A, it could get confusing.
A way to avoid this is to declare the logger as:
protected Logger m_log = Logger.getLogger(this.getClass());
That way the logger gets named as the instance class and not the base
class. (You still would have to make some kind of workaround for
static methods)
Depending on what effect you want to see (i.e. see the logging calls
as coming from superclass implementation or the subclass
implementation) you can use either approach.
Hope that helps,
--
Javier González Nicolini
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]