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 "Stephen Chell (DSL AK)" <St...@datacom.co.nz> on 2004/03/01 04:51:19 UTC

Getting the current class name in static code

In log4j a popular way to name loggers is to name them by software
component.  This can be performed by statically instantiating a logger in
each class, as follows:

package com.foo;
import org.apache.log4j.Logger;

public class Bar {
  static Logger logger = Logger.getLogger(Bar.class);
  
  ...
}

Can anyone think of a generic way to pass the name of the current class to
the getLogger method, without having to name the actual class in the code?
Doing so would enable developers to simply copy and paste that one line of
code into new source files without having to manually modify it to pass in
the new class name.   (Ideally Java needs a static equivalent of "this" to
refer to the current class.)

Cheers
Steve



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