Results 1 to 2 of 2

Thread: Logging entry/exit of methods displays Interface name NOT implementing class.

  1. #1

    Question Logging entry/exit of methods displays Interface name NOT implementing class.

    Hi

    I'm trying this out as my FIRST Learning excercise to spring AOP so bear with me here.

    I'm using Log4J / spring and trying to weave Spring aspects into the code to handle entry/exit logging of all my methods for debugging.

    The Result:

    INFO [http-8888-1] (AspectLogger.java:23) - [AOP] - Entering: INMDOUEngine.execute

    My issue is that the AspectLogger I have coded logs the interface name (the declared type in my bean configuration file) not the concrete implementation of that interface.

    I've tried looking through the JoinPoint class to see if it has methods defined to help me find what I want but so far nothing works as I would like it to.

    The configurations.
    Code:
     <bean id="aspectLogger" class="com.nuance.ndm.ou.util.AspectLogger" />
    
     <aop:config>
      <!-- The Pointcuts. -->
      <aop:pointcut id="loggingPointcut" expression="within(com.nuance.ndm.ou.engines.NTSCalllogEngine)" />
      
      <!-- The Advices. -->
      <aop:aspect id="loggingAspect" ref="aspectLogger">
       <aop:before pointcut-ref="loggingPointcut" method="logEntry" />
       <aop:after pointcut-ref="loggingPointcut" method="logExit" />
      </aop:aspect>
     </aop:config>
    The AspectLogger
    Code:
    public class AspectLogger {
       
       private static org.apache.commons.logging.Log logger = null;
       
       /**
        * Log method entry.
        * @param joinPoint
        */
       public void logEntry( final JoinPoint joinPoint ) {
          String name = joinPoint.getSignature().getDeclaringType().getSimpleName();
          logger = org.apache.commons.logging.LogFactory.getLog( name );
          if( logger.isInfoEnabled() ) logger.info( "[AOP] - Entering: " + name + "." + joinPoint.getSignature().getName() );
       }
    <snipped for brevity>
    }

  2. #2
    Join Date
    Jun 2006
    Location
    SF Bay Area, California
    Posts
    524

    Default

    You can print the class name by using joinPoint.getTarget().getClass().

    -Ramnivas
    Ramnivas Laddad (Follow me on Twitter)
    AspectJ in Action: Enterprise AOP with Spring Applications (2nd edition). Now available!

Tags for this Thread

Posting Permissions

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