I found the same problem as well. It seems that for the same JVM (even with different webapps) all use the same(i.e. the last initialized) config file.
Kenneth
-----Original Message-----
From: James Adams [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 21, 2002 4:25 AM
To: [EMAIL PROTECTED]
Subject: Re: Log4j initialization problem
Hello,
I have tried the ServletContextListener approach suggested below by
Sriram (thanks !) and I am still having the same problem, i.e. I get the
log file (specified in my log4j.properties file) created under whatever
directory I am at when I issue the tomcat start command. It appears
that the log file is being created and placed in the current working
directory if I specify only the file name in the log4j.properties
"File" entry. If I specify the full path, such as
log4j.appender.A1.File=/var/tomcat/webapps/myapp/LogMessages.txt
then it creates and places the file exactly where it the entry
specifies. But I want to just specify the filename and have it created
under the webapp's context directory, that way I won't have to remember
to change the log4j.properties entry whenever the webapp is moved to
another context directory or installed on another machine which might
have a different webapps directory path.
So is there a way to get the log file to be created and placed under its
webapp's context directory ?
Also would it be more appropriate to post this topic/thread to the log4j
user group ([EMAIL PROTECTED]) ?
Thanks in advance for any suggestions or clues.
-James
> Hello,
> I don't have access to my computer right now, but here's roughly what
I
> do to use log4J within my Servlet 2.3 API compliant webapps.
> 1. Create a properties file called log4j.properties
> 2. Place this in WEB-INF folder.
> 3. Write a ContextListener and in the contectInitialized method,
access the
> servlet context. Make sure you place this Listener implementation
along
> with your other classes and that you add an entry for it in web.xml
> 4. Ask the servlet context to get the following resource as a stream
> e.g. InputStream is =
> servletContext.getResourceAsStream("/WEB-INF/log4j.properties");
> 5. Create a properties file that'll initialize with this property
file.
> Properties properties = new Properties();
> properites.load(is);
> is.close();
> 6. Now pass this newly initialized properties object to the
> PropertyConfigurator...
>
> That's it.
>
> Sriram
>
--
To unsubscribe: <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>
-- To unsubscribe: <mailto:[EMAIL PROTECTED]> For additional commands: <mailto:[EMAIL PROTECTED]> Troubles with the list: <mailto:[EMAIL PROTECTED]>
