title: Tomcat can't instantiate org.apache.log4j.varia.LevelMatchFilter class
body: <p>I'm trying to setup <code>log4j</code> on my web app. Web server is <code>Tomcat 7</code>. </p>
  
  <p>I'm getting the following exception:</p>
  
  <pre><code>    log4j:ERROR Could not instantiate class [org.apache.log4j.varia.LevelMatchFilter    ].
      java.lang.ClassNotFoundException: org.apache.log4j.varia.LevelMatchFilter    
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:186)
      at org.apache.log4j.helpers.Loader.loadClass(Loader.java:198)
      at org.apache.log4j.helpers.OptionConverter.instantiateByClassName(OptionConverter.java:326)
      at org.apache.log4j.PropertyConfigurator.parseAppenderFilters(PropertyConfigurator.java:881)
      at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:812)
      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:547)
      at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:483)
      at org.apache.log4j.LogManager.&lt;clinit&gt;(LogManager.java:127)
      at org.apache.log4j.Logger.getLogger(Logger.java:104)
      at org.apache.commons.logging.impl.Log4JLogger.getLogger(Log4JLogger.java:262)
      at org.apache.commons.logging.impl.Log4JLogger.&lt;init&gt;(Log4JLogger.java:108)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
      at org.apache.commons.logging.impl.LogFactoryImpl.createLogFromClass(LogFactoryImpl.java:1025)
      at org.apache.commons.logging.impl.LogFactoryImpl.discoverLogImplementation(LogFactoryImpl.java:844)
      at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:541)
      at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:292)
      at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:269)
      at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:657)
      at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:269)
      at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
      at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
      at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
      at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:649)
      at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1585)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
      at java.util.concurrent.FutureTask.run(FutureTask.java:166)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
      at java.lang.Thread.run(Thread.java:722)
  </code></pre>
  
  <p>I put <code>log4j.properties</code> in the <code>WEB-INF/classes</code> directory as many SO users suggested in other answers to other questions.</p>
  
  <p>I put <code>slf4j-api-1.7.5.jar</code>, <code>slf4j-log4j12-1.7.5.jar</code>, <code>log4j-1.2.16.jar</code> in the <code>WEB-INF/lib</code> directory.</p>
  
  <p>My properties file is the following:</p>
  
  <pre><code>log4j.rootLogger = INFO,infoAppender,errAppender
  
  log4j.appender.infoAppender=org.apache.log4j.DailyRollingFileAppender
  log4j.appender.infoAppender.File= D://logs//info//info.log
  log4j.appender.infoAppender.DatePattern='_'dd-MM-yyyy
  log4j.appender.infoAppender.layout=org.apache.log4j.PatternLayout
  log4j.appender.infoAppender.layout.conversionPattern=%d{dd-MM-yyyy HH:mm:ss} %5p %m%n 
  log4j.appender.infoAppender.filter.infoFilter=org.apache.log4j.varia.LevelMatchFilter    
  log4j.appender.infoAppender.filter.infoFilter.LevelToMatch=INFO    
  log4j.appender.infoAppender.filter.infoFilter.AcceptOnMatch=true   
  log4j.appender.infoAppender.filter.2=org.apache.log4j.varia.DenyAllFilter
  
  
  log4j.appender.errAppender=org.apache.log4j.DailyRollingFileAppender
  log4j.appender.errAppender.File= D://logs//error/err.log
  log4j.appender.errAppender.DatePattern='_'dd-MM-yyyy
  log4j.appender.errAppender.layout=org.apache.log4j.PatternLayout
  log4j.appender.errAppender.layout.conversionPattern=%d{dd-MM-yyyy HH:mm:ss} %5p %m%n 
  log4j.appender.errAppender.filter.errFilter=org.apache.log4j.varia.LevelMatchFilter    
  log4j.appender.errAppender.filter.errFilter.LevelToMatch=ERROR    
  log4j.appender.errAppender.filter.errFilter.AcceptOnMatch=true 
  log4j.appender.errAppender.filter.2=org.apache.log4j.varia.DenyAllFilter 
  </code></pre>
  
  <p>I personally think that problem is in classpath-like issues but all .jar files and .properties file are in the correct place. At least, it's correct according to many related posts that I found.</p>