title: Spring, Log4j within web application
body: <p>I'm trying to use log4j</p>
  
  <p>my log4j.propreties:</p>
  
  <pre><code>log4j.rootLogger=DEBUG, out
  
  log4j.logger.org.springframework=INFO
  log4j.logger.org.apache.activemq=INFO
  log4j.logger.org.apache.activemq.spring=WARN
  log4j.logger.org.apache.servicemix=DEBUG, stdout
  
  log4j.appender.stdout=org.apache.log4j.ConsoleAppender
  log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
  log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} | %-5p | %t | %c | %m%n
  
  log4j.appender.out=org.apache.log4j.DailyRollingFileAppender
  log4j.appender.out.DatePattern=?-?yyyy-MM-dd?.log??/&gt;
  log4j.appender.out.layout=ConversionPattern %d{ABSOLUTE} | %-5p | %t | %c | %m%n
  log4j.appender.out.file=/home/adam/workspace/log/servicemix
  </code></pre>
  
  <p>part of web.xml</p>
  
  <pre><code>&lt;web-app id="WebApp_ID" version="2.5"
      xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
  ...
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          ...
      &lt;/context-param&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;javax.servlet.jsp.jstl.fmt.localizationContext&lt;/param-name&gt;
          &lt;param-value&gt;resources.application&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;log4jConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/classes/config/log4j/log4j.properties&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;log4jRefreshInterval&lt;/param-name&gt;
          &lt;param-value&gt;1000&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.util.Log4jConfigListener&lt;/listener-class&gt;
      &lt;/listener&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  ...
  &lt;/web-app&gt;
  </code></pre>
  
  <p>I added dependencies:</p>
  
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;log4j&lt;/groupId&gt;
          &lt;artifactId&gt;log4j&lt;/artifactId&gt;
          &lt;version&gt;1.2.16&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
          &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
          &lt;version&gt;1.5.2&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>But I'm getting errors:</p>
  
  <pre><code>2011-02-14 03:14:49 org.apache.catalina.core.ApplicationContext log
  INFO: Initializing log4j from [/home/adam/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/CarRentalMaven2XSLTJSPTiles2Tomcat/WEB-INF/classes/config/log4j/log4j.properties]
  log4j:ERROR Could not instantiate class [ConversionPattern %d{ABSOLUTE} | %-5p | %t | %c | %m%n].
  java.lang.ClassNotFoundException: ConversionPattern %d{ABSOLUTE} | %-5p | %t | %c | %m%n
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1671)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1516)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:169)
      at org.apache.log4j.helpers.Loader.loadClass(Loader.java:198)
      at org.apache.log4j.helpers.OptionConverter.instantiateByClassName(OptionConverter.java:326)
      at org.apache.log4j.helpers.OptionConverter.instantiateByKey(OptionConverter.java:123)
      at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:764)
      at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:735)
      at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:615)
      at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:502)
      at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:395)
      at org.apache.log4j.PropertyWatchdog.doOnChange(PropertyConfigurator.java:922)
      at org.apache.log4j.helpers.FileWatchdog.checkAndConfigure(FileWatchdog.java:89)
      at org.apache.log4j.helpers.FileWatchdog.&lt;init&gt;(FileWatchdog.java:58)
      at org.apache.log4j.PropertyWatchdog.&lt;init&gt;(PropertyConfigurator.java:914)
      at org.apache.log4j.PropertyConfigurator.configureAndWatch(PropertyConfigurator.java:461)
      at org.springframework.util.Log4jConfigurer.initLogging(Log4jConfigurer.java:106)
      at org.springframework.web.util.Log4jWebConfigurer.initLogging(Log4jWebConfigurer.java:144)
      at org.springframework.web.util.Log4jConfigListener.contextInitialized(Log4jConfigListener.java:47)
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4544)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5016)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
      at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1035)
      at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:738)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
      at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1035)
      at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:289)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
      at org.apache.catalina.core.StandardService.startInternal(StandardService.java:442)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
      at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:674)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
      at org.apache.catalina.startup.Catalina.start(Catalina.java:596)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:303)
      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:431)
  2011-02-14 03:14:49 org.apache.catalina.core.StandardContext listenerStart
  SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.util.Log4jConfigListener
  java.lang.IllegalArgumentException: Illegal pattern character 'l'
      at java.text.SimpleDateFormat.compile(SimpleDateFormat.java:769)
      at java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:576)
      at java.text.SimpleDateFormat.&lt;init&gt;(SimpleDateFormat.java:501)
      at java.text.SimpleDateFormat.&lt;init&gt;(SimpleDateFormat.java:476)
      at org.apache.log4j.DailyRollingFileAppender.activateOptions(DailyRollingFileAppender.java:226)
      at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:307)
      at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:172)
      at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:104)
      at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:809)
      at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:735)
      at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:615)
      at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:502)
      at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:395)
      at org.apache.log4j.PropertyWatchdog.doOnChange(PropertyConfigurator.java:922)
      at org.apache.log4j.helpers.FileWatchdog.checkAndConfigure(FileWatchdog.java:89)
      at org.apache.log4j.helpers.FileWatchdog.&lt;init&gt;(FileWatchdog.java:58)
      at org.apache.log4j.PropertyWatchdog.&lt;init&gt;(PropertyConfigurator.java:914)
      at org.apache.log4j.PropertyConfigurator.configureAndWatch(PropertyConfigurator.java:461)
      at org.springframework.util.Log4jConfigurer.initLogging(Log4jConfigurer.java:106)
      at org.springframework.web.util.Log4jWebConfigurer.initLogging(Log4jWebConfigurer.java:144)
      at org.springframework.web.util.Log4jConfigListener.contextInitialized(Log4jConfigListener.java:47)
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4544)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5016)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
      at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1035)
      at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:738)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
      at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1035)
      at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:289)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
      at org.apache.catalina.core.StandardService.startInternal(StandardService.java:442)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
      at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:674)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
      at org.apache.catalina.startup.Catalina.start(Catalina.java:596)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:303)
      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:431)
  2011-02-14 03:14:49 com.sun.faces.config.WebConfiguration &lt;init&gt;
  </code></pre>
  
  <p>Should I add any other dependencies related with log4j?</p>