title: Implement logging with AOP and Log4J
body: <p>I try to add automatic logging using aspects to my web app which is developed with Java EE and Spring (core + mvc + security...). Dependencies are managed by maven and the application server is a Glassfish server. The aspect part seems to work but the logging file doesn't get the logs I send through the aspect.</p>
  
  <p>I set the logging configuration in my web.xml adding this:</p>
  
  <pre><code>&lt;listener id="myLogger"&gt;
      &lt;listener-class&gt;org.springframework.web.util.Log4jConfigListener&lt;/listener-class&gt;
  &lt;/listener&gt;
  </code></pre>
  
  <p>The property file is the following (and it works because the log file is well created in my system folders) :</p>
  
  <pre><code># Root logger option
  log4j.rootLogger=INFO, file
  log4j.rootLogger=WARN, file
  log4j.rootLogger=ERROR, file
  # Direct log messages to a log file
  log4j.appender.file=org.apache.log4j.RollingFileAppender
  log4j.appender.file.File=C:\\Users\\chaese\\Documents\\Dev\\LogsMEANS\\logging.log
  log4j.appender.file.MaxFileSize=1MB
  log4j.appender.file.MaxBackupIndex=1
  log4j.appender.file.layout=org.apache.log4j.PatternLayout
  log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
  </code></pre>
  
  <p>I also configured an aspect (using AspectJ) in order to log all information in case of a call to a function starting with "get". Here is the class for this aspect :</p>
  
  <pre><code>import org.apache.log4j.Logger;
  import org.aspectj.lang.annotation.Aspect;
  import org.aspectj.lang.annotation.Before;
  
  @Aspect
  public class PropertyChangeTracker {
  
  private Logger logger = Logger.getLogger(PropertyChangeTracker.getClass());
  
  @Before("execution(String get*(..))")
  public void trackCalls(){
      logger.info("controller called !!");
  }
  }
  </code></pre>
  
  <p>The configuration in aspect-config.xml :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p"
  xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
     http://www.springframework.org/schema/aop 
     http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
  &lt;bean id="propertyChangeTracker" class="services.aspects.PropertyChangeTracker"&gt;   &lt;/bean&gt;
  
  &lt;aop:aspectj-autoproxy&gt;
      &lt;aop:include name="propertyChangeTracker"/&gt;
  &lt;/aop:aspectj-autoproxy&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>I tested this in the debug mode and my "trackCalls" method is called without any trouble but no information gets logged into the log file. I have the feeling there are two different loggers in my app and the one used by the PropertyChangeTracker class is not the one I want... Do you see where I set something wrong?</p>
  
  <p>Thanks in advance for your help!</p>