You missed what I'm trying to do. I'm defining a static logger such as
this:
public class MyClass {
private static final Logger myLogger = Logger.getLogger(MyClass.class);
}
But what I would like to do is this
public class MyClass {
private static final Logger myLogger = Logger.getLogger();
}
Notice the getLogger call has not parameter now. Inside of
Logger.getLogger() it does the stack trace to find the class that it is
being declared in.
I'm working on a Struts2 application with a lot of actions. The tendency is
when creating a new action to find one similar and cut and past it to the
new one. The parameter to the getLogger call is easily missed when renaming
the class name. But with my change the getLogger call automagically figures
out the class in which it is declared. This creates cleaner code that is
easier to maintain.
Brian
On Tue, Jan 27, 2009 at 7:53 PM, Craig P. Motlin <[email protected]> wrote:
> This is a non-issue. If you need to log an object's type, call
> getClass().getName() and log it as a normal message. Stick to one
> private static logger in each class. The logger name will represent
> where the logging statement occurred, not the run time type of the
> logging object.
>
>