File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Runtime method names Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Runtime method names" Watch "Runtime method names" New topic
Author

Runtime method names

Jason Moore
Greenhorn

Joined: Sep 11, 2001
Posts: 10
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

Joined: Apr 20, 2000
Posts: 3252
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).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Runtime method names