I'm using log4j2 (2.0.2) in a servlet 3.0 web application, running in Tomcat 8.0.12. I'm trying to use the weblookup to get the web app context path to use as part of the log file name. (We run the same war file under several different contexts using properties to configure it).
The log4j2.xml file includes
<RollingFile name="Web" fileName="/srv/dnsnet/logs/web-${web:contextPath}.logfile" filePattern="/srv/dnsnet/logs/web-${web:contextPath}-%d{yyyy-MM-dd}-%i.log.gz" append="true" immediateFlush="false">
<PatternLayout>
<Pattern>%d %-5p [%25.25t] %40.40c{3.} %15X{sysid} %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy />
</Policies>
<DefaultRolloverStrategy max="8"/>
</RollingFile>
But the web:contextPath does not get resolved. I have got log4j-web-2.0.2.jar in my web app. I added some messages to the WebLookup class, and the problem is that the external context of the LoggerContext is null.
So I tried to see where the LoggerContext is created. The stack trace when the LoggerContext constructor is called is
at org.apache.logging.log4j.core.LoggerContext.<init>(LoggerContext.java:114)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(ClassLoaderContextSelector.java:218)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:113)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:80)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:82)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:37)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:269)
at org.apache.logging.log4j.jcl.LogFactoryImpl$PrivateManager.getContext(LogFactoryImpl.java:108)
at org.apache.logging.log4j.jcl.LogFactoryImpl.getLoggersMap(LogFactoryImpl.java:52)
at org.apache.logging.log4j.jcl.LogFactoryImpl.getInstance(LogFactoryImpl.java:43)
at org.apache.logging.log4j.jcl.LogFactoryImpl.getInstance(LogFactoryImpl.java:75)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:685)
at org.apache.myfaces.webapp.AbstractMyFacesListener.<clinit>(AbstractMyFacesListener.java:34)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at java.lang.Class.newInstance(Class.java:433)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:151)
at org.apache.catalina.core.ApplicationContext.addListener(ApplicationContext.java:1231)
at org.apache.catalina.core.ApplicationContextFacade.addListener(ApplicationContextFacade.java:647)
at org.apache.jasper.servlet.JasperInitializer.onStartup(JasperInitializer.java:110)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5164)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:581)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1686)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745
But the ClassLoaderContextSelector always passes null for the external context. So it looks as though I'm missing something.
Can anyone suggest what I'm doing wrong, or missing? Do I have to specify a different ContextSelector?
You may have found a bug in log4j. I suspect it is the combination of Commons Logging and the WebLookup that does not work. Can you verify if this is the case (check if the WebLookup works if your application uses the log4j 2 API instead of Commons Logging) and file a bug report in the log4j2 Jira issue tracker?
Related
I am getting this error in my application which is running on EMR
Here are few details about this error
It is not consistent. This error comes once in while (in two days or in a week also).
We have tried building JARs from Local /Jenkins/Maven but no luck. Still this errors appears.
Verified class in the JAR file and it is present at correct location.
It does not look like corrupted jars or class not present issue as this error is not consistent.
Here is the complete stack trace
java.lang.IllegalArgumentException: Cannot parse pattern '%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n'
at org.apache.logging.log4j.core.layout.PatternLayout$SerializerBuilder.build(PatternLayout.java:490)
at org.apache.logging.log4j.core.layout.PatternLayout.<init>(PatternLayout.java:140)
at org.apache.logging.log4j.core.layout.PatternLayout.<init>(PatternLayout.java:61)
at org.apache.logging.log4j.core.layout.PatternLayout$Builder.build(PatternLayout.java:770)
at org.apache.logging.log4j.core.config.AbstractConfiguration.setToDefault(AbstractConfiguration.java:715)
at org.apache.logging.log4j.core.config.DefaultConfiguration.<init>(DefaultConfiguration.java:47)
at org.apache.logging.log4j.core.LoggerContext.<init>(LoggerContext.java:95)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.createContext(ClassLoaderContextSelector.java:254)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(ClassLoaderContextSelector.java:218)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:136)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:123)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:117)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:150)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:196)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:599)
at com.company.search.tcp.rdf.jumper.driver.processclass.processMessages(processclass.java:110)
at com.company.search.ecp.tcp.jumper.driver.processclass.lambda$process$5dfe0a07$1(processclass.java:95)
at org.apache.spark.api.java.JavaRDDLike$$anonfun$foreachPartitionAsync$1.apply(JavaRDDLike.scala:741)
at org.apache.spark.api.java.JavaRDDLike$$anonfun$foreachPartitionAsync$1.apply(JavaRDDLike.scala:741)
at org.apache.spark.SparkContext$$anonfun$37.apply(SparkContext.scala:2212)
at org.apache.spark.SparkContext$$anonfun$37.apply(SparkContext.scala:2212)
at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:90)
at org.apache.spark.scheduler.Task.run(Task.scala:123)
at org.apache.spark.executor.Executor$TaskRunner$$anonfun$10.apply(Executor.scala:408)
at org.apache.spark.util.Utils$.tryWithSafeFinally(Utils.scala:1360)
at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:414)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: zip file closed
at java.util.zip.ZipFile.ensureOpen(ZipFile.java:690)
at java.util.zip.ZipFile.access$200(ZipFile.java:61)
at java.util.zip.ZipFile$ZipEntryIterator.hasNext(ZipFile.java:512)
at java.util.zip.ZipFile$ZipEntryIterator.hasMoreElements(ZipFile.java:507)
at java.util.jar.JarFile$JarEntryIterator.hasNext(JarFile.java:264)
at java.util.jar.JarFile$JarEntryIterator.hasMoreElements(JarFile.java:273)
at org.apache.logging.log4j.core.config.plugins.util.ResolverUtil.loadImplementationsInJar(ResolverUtil.java:347)
at org.apache.logging.log4j.core.config.plugins.util.ResolverUtil.findInPackage(ResolverUtil.java:233)
at org.apache.logging.log4j.core.config.plugins.util.PluginRegistry.loadFromPackage(PluginRegistry.java:225)
at org.apache.logging.log4j.core.config.plugins.util.PluginManager.collectPlugins(PluginManager.java:136)
at org.apache.logging.log4j.core.pattern.PatternParser.<init>(PatternParser.java:132)
at org.apache.logging.log4j.core.pattern.PatternParser.<init>(PatternParser.java:113)
at org.apache.logging.log4j.core.layout.PatternLayout.createPatternParser(PatternLayout.java:255)
at org.apache.logging.log4j.core.layout.PatternLayout$SerializerBuilder.build(PatternLayout.java:473)
... 29 more
we don't use the pattern mentioned in the error stack trace at all .
We use below in our code
name="OFF_File_appender"
fileName="$${sys:spark.yarn.app.container.log.dir}/log4j2.log"
filePattern="$$${sys:spark.yarn.app.container.log.dir}/log4j2.log.%d{yyyy-MM-dd-HH}"
>
<PatternLayout pattern="%d{ISO8601} %-5level %c{3}[%X{currentContext}] - [log4j2] %msg%n"/>
I have a J2EE web application with logback as the logging function
and use Tomcat 7 as the server.
I am using the logback ConsoleAppender right now, so I can go to
/var/log/tomcat7/catalina.out to check the log.
Right now, I want to move the log into a file. I will use a RollingFileAppender to save the log.
I DO NOT want to use a absolute path like:
<appender name="FILE" class="xxx.RollingFileAppender">
<file>/var/log/testFile1.log</file>
<encoder>
<pattern>%msg%n</pattern>
</encoder>
</appender>
I DO NOT want to use a system environment variable, either, like:
<appender name="FILE" class="xxx.RollingFileAppender">
<file>{LOG_LOCATION}\testFile2.log</file>
<encoder>
<pattern>%msg%n</pattern>
</encoder>
</appender>
If I only write the name of log file in the tag, like:
<appender name="FILE" class="xxx.RollingFileAppender">
<file>testFile3.log</file>
<encoder>
<pattern>%msg%n</pattern>
</encoder>
</appender>
I will receive the error:
21:29:45,265 |-ERROR in ch.qos.logback.core.FileAppender[TEST_LOG] - openFile(testFile3.log,true) call failed. java.io.FileNotFoundException: testFile3.log (Permission denied)
at java.io.FileNotFoundException: testFile3.log (Permission denied)
at at java.io.FileOutputStream.open(Native Method)
at at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
at at ch.qos.logback.core.recovery.ResilientFileOutputStream.<init>(ResilientFileOutputStream.java:28)
at at ch.qos.logback.core.FileAppender.openFile(FileAppender.java:149)
at at ch.qos.logback.core.FileAppender.start(FileAppender.java:108)
at at ch.qos.logback.core.joran.action.AppenderAction.end(AppenderAction.java:96)
at at ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:317)
at at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:196)
at at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:182)
at at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:62)
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:149)
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:135)
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:99)
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:49)
at at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75)
at at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:148)
at at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:85)
at at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
at at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)
at at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:107)
at at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:295)
at at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:269)
at at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:156)
at at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132)
at at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:657)
at at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:282)
at at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
at at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
at at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
at at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
at at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
at at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:958)
at at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1599)
at at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at at java.lang.Thread.run(Thread.java:744)
Can I create a log file only with its name?
And if so, where is the default location for the logback log file in Tomcat 7 server?
You want a relative path. Specify <file>./testFile3.log</file>
Check where this gets created by running once.
Note that this could be relative to the location used for launching the application.
I request a test link https://terran.gamebox.com/facebook/issueOrder.jhtml?amount=5&gameId=1&serverId=1&role=role
I can see the message in page
but the exception did not show in catalina.out
This is my configure file
<bean id="exceptionResolver" class="com.gamebox.HandlerException">
HandlerException implements HandlerExceptionResolver
I must point that I can get the other controller's exception such as null pointer exception
I guess it's a spring internal exception, but I need capture all exception in catalina.out file.
I create a #Service dependence in a #Controller, then delete the #Service's class file.
When I started the tomcat, everything is OK, I request this controller, I got the exception message, but the catalina.out show nothing. The tomcat ran in Run mode.
I paste the response message, because this mvc's action will fix next day with this bug, but I will trace nothing in my platform when I use a ajax with mvc in future if it doesn't show in catalina.out and I will be defficult to find nothing.
I am sure it involved transactionManager
java.lang.ClassNotFoundException: com.gamebox.service.FacebookPayOrderService
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
java.lang.Class.getDeclaredFields0(Native Method)
java.lang.Class.privateGetDeclaredFields(Class.java:2300)
java.lang.Class.getDeclaredFields(Class.java:1745)
org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:374)
org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(PersistenceAnnotationBeanPostProcessor.java:322)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:846)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:498)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1117)
org.springframework.web.method.HandlerMethod.createWithResolvedBean(HandlerMethod.java:220)
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:240)
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:56)
org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandler(AbstractHandlerMapping.java:298)
org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1091)
org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1076)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:896)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
com.planetj.servlet.filter.compression.CompressingFilter.doFilter(CompressingFilter.java:270)
com.gamebox.filter.SiteStatusFilter.doFilterInternal(SiteStatusFilter.java:51)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
All system out/error will go to catalina.out by default. Don't use System.out.println, use a logging API and configure your logger to write to the console.
If you are using something like logback, in your application just consider it to write to console:
http://logback.qos.ch/manual/configuration.html
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="debug">
<appender-ref ref="STDOUT" />
</root>
</configuration>
to tame spring messages, you can remove commons-logging and use slf4j to route spring into the same logging. See this article
http://www.codingpedia.org/ama/how-to-log-in-spring-with-slf4j-and-logback/
That should help improve visibility and give you your goal of getting everything into catalina.out.
Finally, I find the solution and I am very satisfy.
Only one changed, edit the TOMCAT_HOME/conf/logging.properties file then locate this line:
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.FileHandler
Append , java.util.logging.ConsoleHandler to this line.
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
All exceptions will be write to catalina.out file.^_^
I'm trying to setup log4j on my web app. Web server is Tomcat 7.
I'm getting the following exception:
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)
I put log4j.properties in the WEB-INF/classes directory as many SO users suggested in other answers to other questions.
I put slf4j-api-1.7.5.jar, slf4j-log4j12-1.7.5.jar, log4j-1.2.16.jar in the WEB-INF/lib directory.
My properties file is the following:
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
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.
i met this question too, finally i find the root lies in log4j.properties file. you have extra space in your properties file. just like your exception points out: log4j:ERROR Could not instantiate class [org.apache.log4j.varia.LevelMatchFilter ]
no extra space expected after LevelMatchFilter.
Here is mine
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.filter.a=org.apache.log4j.varia.LevelMatchFilter
log4j.appender.stdout.filter.a.LevelToMatch=INFO
log4j.appender.stdout.filter.b=org.apache.log4j.varia.DenyAllFilter
OK, I found solution. Use log4j.xml instead of log4j.properties.
Hm, looks strange. I know that only xml supports filters. But I also read in some SO answer that log4j.properties file supports filters for 1.2.16 version. Anyway I recommend use xml.
I implemented log4j logging in my JSF application.My log4j.properties file is like this
log4j.rootLogger=DEBUG, stdout, fileout
#----------------------------- All logging to console-----------------------------
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%d] [%t] %5p %c{1}:%L - %m%n
# ------------------------------ All Logging to File------------------------------
log4j.appender.fileout = org.apache.log4j.RollingFileAppender
log4j.appender.fileout.layout = org.apache.log4j.PatternLayout
log4j.appender.fileout.layout.ConversionPattern = [%d] [%t] %5p %c{1}:%L - %m%n
log4j.appender.fileout.File = ${catalina.home}/logs/Portal-alllogs.log
log4j.appender.fileout.MaxFileSize =2MB
log4j.appender.fileout.MaxBackupIndex =2
Now i get the following exception in my application because the DB is down
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (ORA-01034: ORACLE not available
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:361)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:485)
at org.apache.tomcat.dbcp.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
at org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
WARNING: Failed to register in JMX: javax.naming.NamingException: Cannot create PoolableConnectionFactory (ORA-01034: ORACLE not available
The problem is the above exception shows up in catalina.out,but not in my log file
Can anybody please explain why?
Thanks in advance
Update:I just see this log while deploying the WAR file
WARNING: Unexpected exception resolving reference
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux-x86_64 Error: 2: No such file or directory
)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getLogWriter(BasicDataSource.java:1098)
at org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory.createDataSource(BasicDataSourceFactory.java:350)
at org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory.getObjectInstance(BasicDataSourceFactory.java:156)
at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:143)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
at org.apache.naming.NamingContext.lookup(NamingContext.java:826)
at org.apache.naming.NamingContext.lookup(NamingContext.java:145)
at org.apache.naming.NamingContext.lookup(NamingContext.java:814)
at org.apache.naming.NamingContext.lookup(NamingContext.java:159)
at org.apache.catalina.core.NamingContextListener.addResource(NamingContextListener.java:1021)
at org.apache.naming.NamingContext.lookup(NamingContext.java:159)
at org.apache.catalina.core.NamingContextListener.addResource(NamingContextListener.java:1021)
at org.apache.catalina.core.NamingContextListener.createNamingContext(NamingContextListener.java:631)
at org.apache.catalina.core.NamingContextListener.lifecycleEvent(NamingContextListener.java:237)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:89)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5103)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:812)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:787)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:607)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:932)
at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:723)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:932)
at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:723)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:470)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1322)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:89)
at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:379)
at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:324)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1041)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:774)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1033)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1033)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:291)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:727)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.startup.Catalina.start(Catalina.java:620)
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)
Are you sure the exception is actually LOGGED to stdout, not just PRINTED to stdout? Can you spot the conversion pattern working on what you get to your console?
It may be a permissions problem - check the owners and permissions of the ${catalina.home}/logs directory.
Do you catch that exception in your code and handle it, that is log it? If not, why do you expect to show up in your log?
If it's not a permissions problem: verify that ${catalina.home} resolves to where you think it does -- try using a "raw" absolute path to rule that out.