File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "Runtime method names" Watch "Runtime method names" New topic

Runtime method names

Jason Moore

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:
public class ClassName
public void methodName()
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?
Peter den Haan
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:
subject: Runtime method names
It's not a secret anymore!