Results 1 to 7 of 7

Thread: MethodInvocation and logging.

  1. #1

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

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

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3

    Default

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

    com.mycompany.myclass.mymethod ENTRY

    - Vinay

  4. #4
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    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:
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  5. #5
    Join Date
    Oct 2004
    Posts
    2

    Default 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

  6. #6
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

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

    Spring Modules Team
    http://irbouh.blogspot.com/

  7. #7
    Join Date
    Oct 2004
    Posts
    2

    Default

    worked like a charm, thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •