PDA

View Full Version : MethodInvocation and logging.


Vinay Aggarwal
Aug 17th, 2004, 01:15 PM
I am trying to create a wrapper for a bean that will log every time a method is called on the class. This is straight from the reference documentation. I have written an interceptor that prints the "before" and "after" log statements as in the documentation. However I have run into one problem. The class in documentation logs as follows:

System.out.println("Before: invocation=[" + invocation + "]");

I do not want to call invocatiaon.toString() but use my specific format. I want to log as <packagename>.<classname>.<methodname> ENTRY.

However to do this, I need to get hold of the target class name. But there seems to be no way to get to it. Any ideas?

Should the class have a getTarget() method in the org.springframework.aop.framework.ReflectiveMethod Invocation class?

irbouho
Aug 17th, 2004, 01:44 PM
System.out.println(invocation.getStaticPart().toSt ring());

returns full method signature.

Vinay Aggarwal
Aug 17th, 2004, 04:18 PM
But I do not want full method signature. I am looking to print somethng like this:

com.mycompany.myclass.mymethod ENTRY

- Vinay

irbouho
Aug 17th, 2004, 04:44 PM
is it too hard to convert

public java.lang.String com.mycompany.myclass.mymethod(java.lang.Integer)

into

com.mycompany.myclass.mymethod ENTRY

:wink:

depeupleur
Oct 15th, 2004, 07:42 PM
I have a similar problem where my Proxies, only return the Interface name and not the class name. They were created with BeanNameAutoProxyCreator.

When i do Invocation.getMethod().getDeclaringClass().getName () I get the Interface. Same thing happens with getStaticPart() Is there a convenience method for getting the Target class?

Regards
depeupleur

irbouho
Oct 16th, 2004, 09:14 AM
You can use the following:
String targetName = invocation.getThis().getClass().getName();

HTH

depeupleur
Nov 17th, 2004, 10:33 AM
worked like a charm, thanks