Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] How to get caller method name, little urgent.

Hi all !

I want to get the caller method name which calls a particular api.
So ideally i should get "testMethod" when ever i call "logData" method.

There is another question related to this after earlier part is complete I want to use "aspectJLogging" method when ever "logData" method is called.
Please suggest this as well.

I had attached the files.

I would be very thankful for your help.

Many Thanks
Rajat




package logger;
import java.util.logging.Level;
import java.util.logging.Logger;

public class LogExample {
      public static final Logger logger = Logger.getLogger(LogExample.class.toString());
      
      public void testMethod(){
            for(int i = 0; i < 10; i++){
            	logData(i);
            }
      }     
      
      public  void logData(int i){
    	  logger.log(Level.INFO, Integer.valueOf(i).toString());
      }
      
      public  void aspectJLogging(int i, String className, String methodName){
    	  logger.logp(Level.INFO, className , methodName, Integer.valueOf(i).toString());
      }
      
      public static void main(String []args){
            long initTime = System.currentTimeMillis();
            new LogExample().testMethod();
            System.out.println("Time taken = " + (System.currentTimeMillis() - initTime) + " ms.");
      }
}

Attachment: AspectJLogger.aj
Description: Binary data


Back to the top