You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Philip Denno <pd...@tsi.bc.ca> on 2007/10/26 22:41:45 UTC
RE: [BULK] Getting log4j.properties out of WEB-INF/classes
You could load your property file using the ResourceBundle API and then
pass the resulting Properties object to PropertyConfigurator.
Cheers,
Philip.
-----Original Message-----
From: Troy Davis [mailto:troy@metaphorinteractive.com]
Sent: Friday, October 26, 2007 1:35 PM
To: log4j-user@logging.apache.org
Subject: [BULK] Getting log4j.properties out of WEB-INF/classes
Importance: Low
Hello,
I sent this message last week, but haven't seen any responses. Would
anyone please point me in the right direction?
Thank You,
Troy
---
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: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
__________________
IMPORTANT NOTICE
Email from TSI Terminal Systems Inc. (TSI) is confidential and may be legally privileged. If it is not intended for you, please delete it immediately unread. Under no circumstances should this e-mail be redistributed without prior written consent of TSI. The internet cannot guarantee that this communication is free of viruses, interception or interference and anyone who communicates with us by email is taken to accept the risks in doing so. Without limitation, TSI and its affiliates accept no liability whatsoever and howsoever arising in connection with the use of this email. Under no circumstances shall this email constitute a binding agreement for provision of services by TSI, which is subject to the terms and conditions of TSI's standard schedule for Terminal Tariffs which is also available at http://www.tsi.bc.ca.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org