Re: Getting calling className in Java.Util.Logging.Logger



Hi,
properly this helps you ....

StackTraceElement[] stack =
Thread.getAllStackTraces().get(Thread.currentThread());
for (int i = 0; i < stack.length; i++) {
StackTraceElement elem = stack[i];
System.out.println("Class "+ elem.getClassName() + " Method" +
elem.getMethodName());
}
I think form here you can go on..

Gugle schrieb:

Hi,
I'm using Java 1.5 and I'm using Java's Logger class for logging. I
would like to know how to get the className and methodname of the
calling method for logging(like log4j does). For e.g., if I'm calling
the log method from method a of class B, then the log message should
contain the classname and method name. I don't want to pass the method
name and class name everytime to the log method. Can someone let me
know how this can be done?

.



Relevant Pages