aspose file tools*
The moose likes Tomcat and the fly likes Problem accessing log4j configuration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Problem accessing log4j configuration" Watch "Problem accessing log4j configuration" New topic
Author

Problem accessing log4j configuration

Kristjan Veskimae
Greenhorn

Joined: Oct 08, 2012
Posts: 1
I have my log4j conf file at
Tomcat\webapps\myapp\WEB-INF\classes
and I have a ServletContextListener registered in my web.xml.

In the context listener startup I register my Spring and log4j conf file
DOMConfigurator.configure("logconf.xml"); (log4j)
ApplicationContext ctx = new ClassPathXmlApplicationContext("springconfig.xml"); (Spring)

For some reason I keep getting
log4j:ERROR Could not parse file [logconf.xml].
java.io.FileNotFoundException: C:\Tomcat\bin\logconf.xml (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:97)
at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:90)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:188)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:629)
at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:189)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:799)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:240)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:300)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:205)
at org.apache.log4j.xml.DOMConfigurator$1.parse(DOMConfigurator.java:749)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:866)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:755)
at org.apache.log4j.xml.DOMConfigurator.configure(DOMConfigurator.java:891)
at com.littlech.rps.gs.ContextLoadingListener.contextInitialized(ContextLoadingListener.java:39)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4701)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5204)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5199)
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 do not include any more path than the file name as the argument in both Spring and log4j configuring.

Why does it keep searching for log4j conf file from the wrong place, although I also configure Spring from the same place without problems?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

Welcome to the JavaRanch, Kristjian!

You specified a relative log4j configuration file path. You need to specify an absolute path.

OR

You need to configure log4j using a configuration method that uses the application classpath instead of a file path.

Actually, the best place to ask this sort of question is in our log4j forum, since Tomcat doesn't actively involved itself in webapp logging. There are more log4j experts over there.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
Consider Paul's rocket mass heater.
 
subject: Problem accessing log4j configuration