Results 1 to 3 of 3

Thread: log4j debugging using AOP

  1. #1
    Join Date
    Feb 2006
    Location
    Paris, France
    Posts
    13

    Default log4j debugging using AOP

    I can't find a way that would make Spring intercept all calls to all methods of any class (and not only interfaces) of my application and then log, with log4j how the method was called (which arguments on which objects) and what the method has returned.

    I suppose this is very basic utilisation of Spring but I can't find a way to do this the simpliest possible way (I've managed to make that only with classes implementing interfaces and making a ProxyFactoryBean for every bean I create what is very verbose XML).

    Does anyone have an idea how I could make this ?

    Thanks.

    Mick.

  2. #2
    Join Date
    Oct 2004
    Location
    Herndon, VA, US
    Posts
    648

    Default

    I would just use aspectj or aspectwerkz for this kind of "heavy" stuff. For example, it'd be rather trivial to implement a tracing aspect in aspectj.
    --Jing Xue

  3. #3
    Join Date
    Feb 2006
    Location
    Paris, France
    Posts
    13

    Default

    Finally I've chosen the following solution :

    I've created an isolated xml file :

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    
    <beans>
    
    	<bean id="debugAdvisor"
    		class="aop.debug.LoggerEntreeSortieInterceptor"
    		lazy-init="true" />
    
    	<bean id="proxyCreator"
    		class="aop.debug.LoggerEntreeSortieAutoProxyCreator"
    		lazy-init="true">
    		<property name="interceptorNames">
    			<list>
    				<value>debugAdvisor</value>
    			</list>
    		</property>
    		<property name="beanNames">
    			<list>
    				<value>*</value>
    			</list>
    		</property>
    	</bean>
    
    </beans>
    with :
    - LoggerEntreeSortieInterceptor (and now you know i'm french) extending Spring Framework's DebugInterceptor to customize how input/output data are logged.
    - LoggerEntreeSortieAutoProxyCreator extending BeanNameAutoProxyCreator reimplementing isMatch to decide which beans i want to be proxied and which ones i don't want to be proxied

    Then i just have to comment/decomment the "<import resource="" />" line in my main Spring config file to deactivate/activate the logging of input and output parameters without any change in my code.

    Of course, the limitation is that this only works for interface's methods and not for every method of every object in my application (although this can be achieved quite easily but only with setter injection because of the following bug : http://opensource2.atlassian.com/pro...nQqrM?page=all) but it has already turned out to be pretty useful.

Posting Permissions

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