I am using Tomcat/4.1.12 and trying to initialize Log4j with a properties
file and java servlet. It logs just fine to the console and when starting
up it appears to load the properties file without error, but it never
creates the log file (admin.log). My properties file is stored in the
WEB-INF/classes folder.
I can get it to create the log file by programmatically configuring log4j,
but I would like to get away from that.
Anybody have any ideas?
Does anybody know where it would create this file by default?
Thanks in advance,
Shawn Smith
------------------------------------
Here is my properties file:
#start
log4j.rootLogger=debug, stdout, cadtutorOut
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
log4j.appender.cadtutorOut=org.apache.log4j.RollingFileAppender
log4j.appender.cadtutorOut.File=admin.log
log4j.appender.cadtutorOut.MaxFileSize=100KB
log4j.appender.cadtutorOut.MaxBackupIndex=1
log4j.appender.cadtutorOut.layout=org.apache.log4j.PatternLayout
log4j.appender.cadtutorOut.layout.ConversionPattern=%p %t %c - %m%n
log4j.category.org.apache.torque=debug, cadtutorOut
log4j.category.com.cadtutor=debug, cadtutorOut
#end
Loaded with a initialization servlet (copied directly from the log4j
manual):
//start
package com.cadtutor.controller;
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 {
public
void init() {
String prefix = getServletContext().getRealPath("/");
String file = getInitParameter("log4j-init-file");
System.out.print("Getting log4j.properties from "+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) {
}
}
//end
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]