Getting class name without instance?
From: Sibyl (sibyltalk_at_yahoo.com)
Date: 11/27/03
- Next message: Alex Hunsley: "Re: Problem with double buffering"
- Previous message: David: "Problem with double buffering"
- Next in thread: Chris: "Re: Getting class name without instance?"
- Reply: Chris: "Re: Getting class name without instance?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 27 Nov 2003 14:56:30 -0600
Is there any way to get the name of a class without an instance (i.e.,
object of the class)? I am working with log4j, and would like a uniform
way to name loggers without typing in the name of the class for each
individual class. For example,
------------
import org.apache.log4j.Logger;
public class Foo {
...
private static Logger logger = Logger.getLogger([get either Class
object or class name here--the result should be the Class Foo.class or
its fully qualified name as a String]);
}
------------
The point is that this same statement needs to be in every class where
logging is done, and I would like them all to be identical.
================================================
Question 2:
A related question is how to get the name and signature of the method
(this time in an object) that a statement appears in. I.e.,
-----------
public class Foo {
public void bar(String s) {
System.out.println("I am now in " + [get method name and
signature--the result should be "bar(String s)" or the equivalent]);
}
}
------------
This second question relates to having the logger record the name of the
active method in a way that is uniform across all classes and methods.
Thanks for your help!
Sibyl
- Next message: Alex Hunsley: "Re: Problem with double buffering"
- Previous message: David: "Problem with double buffering"
- Next in thread: Chris: "Re: Getting class name without instance?"
- Reply: Chris: "Re: Getting class name without instance?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]