Announcement Announcement Module
Collapse
No announcement yet.
MethodInvocation and logging. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MethodInvocation and logging.

    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?

  • #2
    Code:
      System.out.println&#40;invocation.getStaticPart&#40;&#41;.toString&#40;&#41;&#41;;
    returns full method signature.

    Comment


    • #3
      But I do not want full method signature. I am looking to print somethng like this:

      com.mycompany.myclass.mymethod ENTRY

      - Vinay

      Comment


      • #4
        is it too hard to convert
        Code:
          public java.lang.String com.mycompany.myclass.mymethod&#40;java.lang.Integer&#41;
        into
        Code:
          com.mycompany.myclass.mymethod ENTRY
        :wink:

        Comment


        • #5
          How to get the Target name

          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

          Comment


          • #6
            You can use the following:
            Code:
                String targetName  = invocation.getThis&#40;&#41;.getClass&#40;&#41;.getName&#40;&#41;;
            HTH

            Comment


            • #7
              worked like a charm, thanks

              Comment

              Working...
              X