log4j and Tomcat-problem

Hi all,

First I tried to add some logging to my simple Java code with a xml configuration file and it worked fine.

Now I am trying to add logging to the whole java application in the same way which runs in tomcat and face with the foll problem.Tomcat is not able to find the configuration file.I tried to place the xml file in all feasible locations in tomcat and also tried to add in classpath but in vain.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`

Java Code(Which gets called in startup by another code)

Java Code

public class PublisherPoll implements Runnable {

public static Logger logger = Logger.getLoggerPublisherPoll.class);//***********log4j

public static Logger getLoggerInstance(){//***********log4j

return logger;

}

static{

DOMConfigurator.configure("sudarson.xml");//**********its telling it cant find/open this xml file

}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Error(during starting tomcat)

log4j:ERROR Could not open [sudarson.xml].

java.io.FileNotFoundException: sudarson.xml (The system cannot find the file sp

cified)

at java.io.FileInputStream.open(Native Method)

at java.io.FileInputStream.<init>(FileInputStream.java:106)

at java.io.FileInputStream.<init>(FileInputStream.java:66)

at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.jav

:583)

at org.apache.log4j.xml.DOMConfigurator.configure(DOMConfigurator.java:

87)

at SerenaStartupServlet.init(SerenaStartupServlet.java:44)

at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper

java:1091)

at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:9

5)

[1782 byte] By [sudarsona] at [2007-10-1 23:42:36]
# 1

> DOMConfigurator.configure("sudarson.xml");//**********its telling it cant find/open this xml file

What does "sudarson.xml" mean to you? To me, it means a file name relative to the current directory. What do you think the current directory is when you're running this in Tomcat?

You need to research the APIs more fully, to figure out how to give it a resource name relative to the application's classpath, and put that file in said classpath.

If I were you, I would try to avoid explicitly calling DOMConfigurator.configure altogether, and just pass the appropriate Log4J system property to the commandline that starts up Tomcat. Let Log4J worry about loading the file, given the property. If I recall correctly, the system property name is "log4j.configuration", which defaults to "log4j.properties" if unspecified. Also, rather than have each application running in Tomcat have their own log4j configuration file name, I'd name them something more universal, like "log4j.xml" - then if you deploy multiple apps in Tomcat, they can all load their own log4j.xml file, as long as (again) you corrected the "log4j.configuration" system property.

warnerjaa at 2007-7-15 15:32:53 > top of Java-index,Java Essentials,New To Java...
# 2
By the way, thanks (NOT) for duplicating this topic. http://forum.java.sun.com/thread.jspa?threadID=662864Would you like people to keep answering in both threads, duplicating their answers and thus wasting their time, or what?
warnerjaa at 2007-7-15 15:32:53 > top of Java-index,Java Essentials,New To Java...