Results 1 to 6 of 6

Thread: Problem performance Logging using Spring AOP

  1. #1
    Join Date
    Nov 2011
    Posts
    18

    Default Problem performance Logging using Spring AOP

    Hi all,

    I am trying to implement performance logging using Spring AOp in my application. But it creates only an empty log file:

    Following are the configuration I am doing:
    In application context:

    Code:
    <bean id="springMonitoringAspectInterceptor" class="org.springframework.aop.interceptor.PerformanceMonitorInterceptor">				
    </bean>	
    			
    <aop:config>       		
    	<aop:pointcut id="springMonitoringPointcut" expression="execution(* com.project14.service.common.AppService.execute(..))"/>                           	                            		
    	<aop:advisor pointcut-ref="springMonitoringPointcut" advice-ref="springMonitoringAspectInterceptor"/>      	
    </aop:config>
    In log4j config xml:
    Code:
      <appender name="perfLog" class="org.apache.log4j.DailyRollingFileAppender">
          <param name="Threshold" value="INFO" />
          <param name="File" value="${catalina.home}/logs/dashboard_pref.log"/>
          <param name="DatePattern" value="'-'yyyy-MM-dd'.log'"/>
          <layout class="org.apache.log4j.PatternLayout">
             <param name="ConversionPattern" value="[%d{ISO8601}] - %-5p- [%X{USER_ENCRYPT_ID}%x] - %C.%M(%F:%L) - %m %n" />
          </layout>
       </appender>
    
       <logger name="org.springframework.aop.interceptor.PerformanceMonitorInterceptor" additivity="false">
            <level value="TRACE"/>
            <appender-ref ref="perfLog"/>
        </logger>
    aopalliance-1.0.jar
    aspectjweaver-1.6.8.jar are in class path. There is no compilation error.

    AppService is an interface all the service class implements it's execute method. I want to log execution time of excute method of each service.
    I am using spring 3.0 libraries for this project.
    Please help.

  2. #2
    Join Date
    Jun 2011
    Posts
    35

    Default

    I've not tested your example but if com.project14.service.common.AppService is an interface you should probably use the pointcut expresion
    execution(* com.project14.service.common.AppService+.execute(..))
    The + sign indicates that it should match any subtype of AppService.

  3. #3
    Join Date
    Nov 2011
    Posts
    18

    Default

    No its not working. Again black log file

  4. #4
    Join Date
    Jun 2011
    Posts
    35

    Default

    In the log4j config your appender has threshold INFO.
    Since perflogging is on TRACE level you need to change that to TRACE for the appender.

    As it is now the logging will be done on the logger but filtered out in the appender.

    If the "execute" method is defined in the interface you do not need the plus sign in the expression.

  5. #5
    Join Date
    Nov 2011
    Posts
    18

    Default

    Thanks its working,
    But the output message is not as per expectation.


    Code:
    [2011-12-12 16:25:04,038] - DEBUG- [03408929B88F770CDD3F1DB440D93E05-f5b5d3595709e3209bf74cb1b53618ec-Deepanssssss] - org.springframework.aop.interceptor.PerformanceMonitorInterceptor.invokeUnderTrace(PerformanceMonitorInterceptor.java:65) - StopWatch 'com.project14.service.common.AppService.execute': running time (millis) = 5391
    Since all services implements AppService.execute and point cut is also defined on that, its printing interface name (AppService.execute) for all service classes, in steed of actual class name. So not able to identify which service is taking what time.

    Any suggestion

  6. #6
    Join Date
    Jun 2011
    Posts
    35

    Default

    Set the LogTargetClassInvocation property of PerformanceMonitorInterceptor to true:
    Code:
     
     <bean id="springMonitoringAspectInterceptor"
             class="org.springframework.aop.interceptor.PerformanceMonitorInterceptor">
           <property name="LogTargetClassInvocation" value="true" />
       </bean>
    or force the use of CGLIB proxies by adding proxy-target-class="true" to aop:config.
    Code:
     <aop:config proxy-target-class="true">

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
  •