This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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).]
 
wood burning stoves
 
subject: Runtime method names
 
Similar Threads
namespaces
ErrorLog class with flexibility of println
How to user polymophism??
class name
encapsulating static variables