Alessio Stalla wrote :
On Sep 9, 5:18 pm, Wojtek <nowh...@a.com> wrote:
This has probably been hashed to death, however,
It these a way to extract the name of the method from within that
method?
public String getFoo()
{
Log.trace(this.class.GetName(), "getFoo", "I am in the method");
return "Foo";
}
public String getFooBar()
{
Log.trace(this.class.GetName(), "getFooBar", "I am in the method");
return getFoo() + "Bar";
}
If you are using this for logging, chances are that your log
implementation already does what you want, and you just have to tell
it to print the method name. Log4j for example supports this.
Else, you can inspect the return value of Thread.currentThread
().getStackTrace(). You can study the log4j source code to see how
they do it.
Yes, but that takes runtime cycles which I am loathe to waste on
logging. Besides the method name is also used in other places such as:
sql.commit("methodName");
I know I can set up a:
final String methodName="Foo";
but again that is runtime expense and also means that if I refactor the
method name, then I also need to change the text.
Something cheap, preferrably done by the compiler as a compiler
directive, rather than a runtime action.
compile-time. Look for different AoP implementations, you might find
one you want.