Announcement Announcement Module
No announcement yet.
log4j debugging using AOP Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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 ?



  • #2
    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.


    • #3
      Finally I've chosen the following solution :

      I've created an isolated xml file :

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "">
      	<bean id="debugAdvisor"
      		lazy-init="true" />
      	<bean id="proxyCreator"
      		<property name="interceptorNames">
      		<property name="beanNames">
      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 : but it has already turned out to be pretty useful.