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 Thai Thanh Ha <th...@psv.com.vn> on 2001/03/12 12:23:00 UTC
Can't use log4j.properties with my servlet
Hi all!
I have a problem with my servlet. I want to use log4j.properties to
configure Log4J. I have put log4j.properties in /WEB-INF/classes. I think
that Log4J will look for log4j.properties in the classpath if I don't use
BasicConfigurator.configure() . But Log4J couldn't find log4j.properties.
What's wrong? Please help me!
This is my servlet
--------------------------
public class MyActionServlet extends org.apache.struts.action.ActionServlet
{
static Category cat =
Category.getInstance(MyActionServlet.class.getName());
/** Creates new MyActionServlet */
public MyActionServlet() {
}
public void init() throws javax.servlet.ServletException {
super.init();
// Congigure for Log4J
// Won't use default values. Will use log4j.properties from class
loader
//BasicConfigurator.configure();
cat.debug("Configure() completed.");
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
....
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
.........
}
}
------------------
But I always received this error:
log4j:ERROR No appenders could be found for category (MyActionServlet).
log4j:ERROR Please initialize the log4j system properly.
-----------------
This is my log4j.properties file
# Set root category priority to DEBUG and its only appender to A1.
log4j.rootCategory=INFO, A1
# A1 is set to be a FileAppender which outputs to System.out.
log4j.appender.A1=org.apache.log4j.FileAppender
log4j.appender.A1.File=System.out
# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
--------------------------------
Regards,
Thai
Re: Can't use log4j.properties with my servlet
Posted by Robert Burrell Donkin <Ro...@appleonline.net>.
Thai Thanh Ha wrote:
> Hi all!I have a problem with my servlet. I want to use
> log4j.properties to configure Log4J. I have put log4j.properties in
> /WEB-INF/classes. I think that Log4J will look for log4j.properties in
> the classpath if I don't use BasicConfigurator.configure() . But Log4J
> couldn't find log4j.properties. What's wrong? Please help me!
what container are you using? your servlet doesn't actually run like it
would in a free environment.
if you are using tomcat 4 i do have a very rough servlet listener which
loads log4j from a path relative to you context. i can post it to the
list if it's any use.
if you want to roll your own, i started by using a PropertyConfigurator
and the ServletContext to find an absolute path from a location relative
to your web app.
- robert
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org