log4j
Web アプリでセットアップしようとしています。ウェブサーバーはTomcat 7
.
次の例外が発生します。
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.<clinit>(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.<init>(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)
多くのSOユーザーが他の質問に対する他の回答で提案したようlog4j.properties
に、ディレクトリに入れました。WEB-INF/classes
slf4j-api-1.7.5.jar
、、slf4j-log4j12-1.7.5.jar
をディレクトリに入れlog4j-1.2.16.jar
ました。WEB-INF/lib
私のプロパティファイルは次のとおりです。
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
私は個人的に問題はクラスパスのような問題にあると思いますが、すべての .jar ファイルと .properties ファイルは正しい場所にあります。少なくとも、私が見つけた多くの関連記事によると、それは正しいです。