Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Runtime method names

 
Jason Moore
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know if there is a way to get the name of the currently executing method?
I'm trying to get this information so I can add it to an error log when errors occur. I imagine making a call to a static method from within the method where the error occurrs. For instance:
<code>
public class ClassName
{
public void methodName()
{
ErrorLogger.logError(Utilities.getMethodName());
}
}
So in this case I would define a static method in the Utilities class that would return the name of the current method as a String. Can this be done?
Thanks.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't reinvent the wheel, use Log4J. If you have to reinvent the wheel, then at least steal it - log4j can print the source file and line number of every logging call. Don't know how. Download the source and find out.
- Peter

[This message has been edited by Peter den Haan (edited October 25, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic