Options (roughly decreasing recommendations):
1. Move to a share location like tomcat/common/classes
2. Set a system property to give the path to log4j.properties (I
forgot the name)
3. Explicitly call configure.
On 10/24/07, Troy Davis <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I've been trying to get log4j to load my properties file from
> somewhere other than WEB-INF/classes, mostly because eclipse clears
> out this directory when I choose Project -> Clean. I've tried a few
> different approaches that I found online, including this:
>
> (inside web-app block of web.xml):
>
> <servlet>
> <servlet-name>log4j-init</servlet-name>
> <servlet-class>com.m4.Log4jInit</servlet-class>
> <init-param>
> <param-name>log4j-init-file</param-name>
> <param-value>WEB-INF/log4j.properties</param-value>
> </init-param>
> <load-on-startup>1</load-on-startup>
> </servlet>
>
>
> (full text of Log4jInit.java, compiled and included in a jar in WEB-
> INF/lib):
>
> package com.m4;
> import org.apache.log4j.PropertyConfigurator;
> import javax.servlet.http.HttpServlet;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
> import java.io.PrintWriter;
> import java.io.IOException;
> public class Log4jInit extends HttpServlet {
> private static final long serialVersionUID = -5104057715092254401L;
> public void init() {
> String prefix = getServletContext().getRealPath("/");
> String file = getInitParameter("log4j-init-file");
> System.out.println("Initializing log4j with " + prefix + file);
> // if the log4j-init-file is not set, then no point in trying
> if(file != null) {
> PropertyConfigurator.configure(prefix+file);
> }
> }
> public void doGet(HttpServletRequest req, HttpServletResponse res) {
> // Nothing happening here yet.
> }
> }
>
> I can see the debug line go by when init() is called in Log4jInit,
> but I still get an error saying that log4j is not configured properly.
>
> What is the recommended way to load this file from some other location?
>
> Thank You,
> Troy
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
James A. N. Stauffer http://www.geocities.com/stauffer_james/
Are you good? Take the test at http://www.livingwaters.com/good/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]