Announcement Announcement Module
No announcement yet.
Logging entry/exit of methods displays Interface name NOT implementing class. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

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


    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] ( - [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.
     <bean id="aspectLogger" class="com.nuance.ndm.ou.util.AspectLogger" />
      <!-- 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" />
    The AspectLogger
    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() ) "[AOP] - Entering: " + name + "." + joinPoint.getSignature().getName() );
    <snipped for brevity>

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