Re: Configuration file in a Web Application
Posted By:
Ravindranath_Y
Posted On:
Tuesday, July 13, 2004 07:59 AM
Try the following as it works for me. Put your log4j.properties file under WEB-INF/log4j/log4j.xml
Also place the log4j.dtd under the same directory.
In your web deployment descriptor have an initialization paramter called log4j-init to point to
/WEB-INF/log4j/log4j.xml
And in your servlet init() have the following code..
String prefix = getServletContext().getRealPath("/");
String file = getInitParameter("log4j-init-file");
System.out.println("Reading file" + prefix + file);
if (file != null) {
DOMConfigurator.configureAndWatch(prefix + file, 60000);
}
But if you are using .properties then all you would need to do is in the servlet code
String prefix = getServletContext().getRealPath("/");
String file = getInitParameter("log4j-init-file");
System.out.println("Reading file" + prefix + file);
if (file != null) {
PropertyConfigurator.configure(prefix+file);
}
Good luck!
Thanks
Ravi
Re: Configuration file in a Web Application
Posted By:
Ravindranath_Y
Posted On:
Tuesday, July 13, 2004 07:59 AM
Try the following as it works for me. Put your log4j.properties file under WEB-INF/log4j/log4j.xml
Also place the log4j.dtd under the same directory.
In your web deployment descriptor have an initialization paramter called log4j-init to point to
/WEB-INF/log4j/log4j.xml
And in your servlet init() have the following code..
String prefix = getServletContext().getRealPath("/");
String file = getInitParameter("log4j-init-file");
System.out.println("Reading file" + prefix + file);
if (file != null) {
DOMConfigurator.configureAndWatch(prefix + file, 60000);
}
But if you are using .properties then all you would need to do is in the servlet code
String prefix = getServletContext().getRealPath("/");
String file = getInitParameter("log4j-init-file");
System.out.println("Reading file" + prefix + file);
if (file != null) {
PropertyConfigurator.configure(prefix+file);
}
Good luck!
Thanks
Ravi
Re: Configuration file in a Web Application
Posted By:
Anonymous
Posted On:
Wednesday, July 7, 2004 10:56 AM
use getServletContext().getRealPath("WEB-INF/classes")
from your JSP/Servlet code to get a full path to the lof4j.properties file
This translates the relative path (application path)
to a path like 'C: omcatwebapps heappweb-infclasses'
Re: Configuration file in a Web Application
Posted By:
M_J
Posted On:
Tuesday, June 29, 2004 06:46 AM
Any progress on this? I'm having the same problem.
Thanks.