logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Troy Davis <t...@metaphorinteractive.com>
Subject Getting log4j.properties out of WEB-INF/classes
Date Wed, 24 Oct 2007 17:14:00 GMT

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):


(full text of Log4jInit.java, compiled and included in a jar in WEB- 

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) {
   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,

To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

View raw message