logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Chell (DSL AK)" <Steph...@datacom.co.nz>
Subject Getting the current class name in static code
Date Mon, 01 Mar 2004 03:51:19 GMT
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.)


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

View raw message