Please try getting rid of the initialization servlet and calling your config file log4j.properties and put it in WEB-INF/classes (with log4j.jar in WEB-INF/lib, of course). You're making this overcomplicated. First, get it working with a base-minimum setup. You can add complexity after get your bearings.
Also, I suggest logging to a different file than what Tomcat logs to. Jake Quoting [EMAIL PROTECTED]: > Unfortunately, it is still not logging my debug statements. I took your > advice > and also read through some documents and created a log4j initialization > servlet. > Here is the code and results: > # > # COmmon Logging servlet that starts once > # > public class CommonLogging extends HttpServlet { > > public void init() { > String prefix = getServletContext().getRealPath("/"); > String file = getInitParameter("log4j-init-file"); > if(file != null) { > PropertyConfigurator.configure(prefix+file); > } > } > > public void doGet(HttpServletRequest req, HttpServletResponse res) {} > > public void doPost(HttpServletRequest req, HttpServletResponse res) {} > } > > # > # In web.xml > # > > <servlet> > <servlet-name>log4j-init</servlet-name> > <servlet-class>com.foo.CommonLogging</servlet-class> > > <init-param> > <param-name>log4j-init-file</param-name> > <param-value>WEB-INF/classes/log4j.lcf</param-value> > </init-param> > > <load-on-startup>1</load-on-startup> > </servlet> > > # > # log4j.lcf in WEB-INF/classes > # > log4j.rootCategory=DEBUG, A2 > log4j.appender.A2=org.apache.log4j.DailyRollingFileAppender > log4j.appender.A2.file=logs/tomcat.log > log4j.appender.A2.datePattern='.'yyyy-MM-dd > log4j.appender.A2.append=true > log4j.appender.A2.layout=org.apache.log4j.PatternLayout > log4j.appender.A2.layout.ConversionPattern=%-5p %d{ISO8601} [%t] - %m%n > > # > # TestServlet > # > public class TestServlet extends HttpServlet { > private static Logger logger = > Logger.getLogger(GenerateChartServlet.class.getName()); > > public TestServlet() { > } > > private void doPost(HttpServletRequest req, HttpServletResponse res) > throws IOException, ServletException > { > ... > // This never gets outputted to log file > logger.debug("TestServlet: Debbuging"); > ... > } > } > > # > # Output from tomcat.log > # > Dec 20, 2006 1:55:43 PM org.apache.catalina.core.AprLifecycleListener > lifecycleEvent > Dec 20, 2006 1:55:43 PM org.apache.coyote.http11.Http11BaseProtocol init > INFO: Initializing Coyote HTTP/1.1 on http-80 > Dec 20, 2006 1:55:43 PM org.apache.catalina.startup.Catalina load > INFO: Initialization processed in 751 ms > Dec 20, 2006 1:55:44 PM org.apache.catalina.core.StandardService start > INFO: Starting service Catalina > Dec 20, 2006 1:55:44 PM org.apache.catalina.core.StandardEngine start > INFO: Starting Servlet Engine: Apache Tomcat/5.5.20 > Dec 20, 2006 1:55:44 PM org.apache.catalina.core.StandardHost start > INFO: XML validation disabled > log4j:WARN No appenders could be found for logger > (org.apache.commons.digester.Digester.sax). > log4j:WARN Please initialize the log4j system properly. > DEBUG JspRuntimeContext - Parent class loader is: > WebappClassLoader > delegate: false > repositories: > /WEB-INF/classes/ > ----------> Parent Classloader: > [EMAIL PROTECTED] > DEBUG JspServlet - Scratch dir for the JSP engine is: > DEBUG JspServlet - IMPORTANT: Do not modify the > generated > servlets > Dec 20, 2006 1:55:45 PM org.apache.catalina.core.ApplicationContext log > INFO: org.apache.webapp.balancer.BalancerFilter: init(): ruleChain: > [org.apache.webapp.balancer.RuleChain: > [org.apache.webapp.balancer.rules.URLStringMatchRule: Target string: News / > Redirect URL: http://www.cnn.com], > [org.apache.webapp.balancer.rules.RequestParameterRule: Target param name: > paramName / Target param value: paramValue / Redirect URL: > http://www.yahoo.com], > [org.apache.webapp.balancer.rules.AcceptEverythingRule: > Redirect URL: http://jakarta.apache.org]] > Dec 20, 2006 1:55:45 PM org.apache.catalina.core.ApplicationContext log > INFO: ContextListener: contextInitialized() > Dec 20, 2006 1:55:45 PM org.apache.catalina.core.ApplicationContext log > INFO: SessionListener: contextInitialized() > Dec 20, 2006 1:55:45 PM org.apache.catalina.core.ApplicationContext log > INFO: ContextListener: contextInitialized() > Dec 20, 2006 1:55:45 PM org.apache.catalina.core.ApplicationContext log > INFO: SessionListener: contextInitialized() > Dec 20, 2006 1:55:46 PM org.apache.coyote.http11.Http11BaseProtocol start > INFO: Starting Coyote HTTP/1.1 on http-80 > Dec 20, 2006 1:55:46 PM org.apache.jk.common.ChannelSocket init > INFO: JK: ajp13 listening on /0.0.0.0:8009 > Dec 20, 2006 1:55:46 PM org.apache.jk.server.JkMain start > INFO: Jk running ID=0 time=0/27 config=null > Dec 20, 2006 1:55:46 PM org.apache.catalina.storeconfig.StoreLoader load > INFO: Find registry server-registry.xml at classpath resource > Dec 20, 2006 1:55:46 PM org.apache.catalina.startup.Catalina start > INFO: Server startup in 2322 ms > DEBUG ManagerBase - Start expire sessions StandardManager > at > 1166641005968 sessioncount 0 > DEBUG ManagerBase - End expire sessions StandardManager > processingTime 0 expired sessions: 0 > > Any ideas? Thanks so much for your help!! > > Quoting Jacob Kjome <[EMAIL PROTECTED]>: > > > > > 1. Don't configure from the servlet. Either let Log4j autoconfigure > > itself by finding log4j.properties or log4j.xml in the classpath or > > configure from a class that's guaranteed to be called once (or has > > methods that are guaranteed to be called once) such as a servlet > > context listener. > > > > 2. Where do you expect Log4j to find log4j.properties? I bet you > > didn't expect that it would look in the directory from which the JVM > > started. The String version of the method takes a file path. If you > > give it a relative one, it will look relative to the directory from > > the JVM started. If you started Tomcat from it's script, it's > > looking in CATALINA_HOME/bin for the properties file. Avoid using a > > File. If you configure yourself, use a URL. You can load up a > > resource from the classloader as a URL and pass that to the > > configurator. I would avoid configuring yourself unless you have a > > really good reason to do it, though. > > > > 3. From the looks of it, you have Log4j in common/lib or shared/lib, > > right? You should avoid this too unless you know what you are > > doing. All your app that share this log4j.jar will log to the same > > logger repository. And each time you reconfigure an app, you > > reconfigure *all* apps. Do yourself a favor and put log4j.jar in > > WEB-INF/lib of each app you use and put the config file in > > WEB-INF/classes. Let Log4j autoconfigure itself and you will be golden. > > > > > > Jake > > > > At 09:33 PM 12/19/2006, you wrote: > > >I am trying to use log4j in my application under Tomcat 5.5. However, it > is > > >producing mounds of debugging information but none of it lists the items > I > > >specify. Here is a portion of my application, the config file, and > > a portion of > > >the output. Please note that logger.debug("TestServlet: Debugging) never > > gets > > >printed in the log file even though the function gets called! > > > > > >// TestServlet > > >public class TestServlet extends HttpServlet { > > > private static Logger logger = > > >Logger.getLogger(GenerateChartServlet.class.getName()); > > > > > > public TestServlet() { > > > PropertyConfigurator.configure("log4j.properties"); > > > } > > > > > > private void doPost(HttpServletRequest req, HttpServletResponse > res) > > > throws IOException, ServletException > > > { > > > ... > > > // This never gets outputted to log file > > > logger.debug("TestServlet: Debbuging"); > > > ... > > > } > > >} > > > > > ># > > ># Log4j configuration file. > > ># > > >log4j.rootCategory=DEBUG, A2 > > > > > ># Available levels are DEBUG, INFO, WARN, ERROR, FATAL > > ># > > ># > > ># A2 is a DailyRollingFileAppender > > ># > > > > > >log4j.appender.A2=org.apache.log4j.DailyRollingFileAppender > > >log4j.appender.A2.file=logs/tomcat.log > > >log4j.appender.A2.datePattern='.'yyyy-MM-dd > > >log4j.appender.A2.append=true > > >log4j.appender.A2.layout=org.apache.log4j.PatternLayout > > >log4j.appender.A2.layout.ConversionPattern=%-5p %d{ISO8601} [%t] - %m%n > > > > > ># > > >#OUTPUT > > ># > > >DEBUG 2006-12-19 22:08:11,593 [main] - bodyText='' > > >DEBUG 2006-12-19 22:08:11,593 [main] - Fire body() for > > >ObjectCreateRule[className=org.apache.catalina.deploy.ContextResource, > > >attributeName=null] > > >DEBUG 2006-12-19 22:08:11,593 [main] - Fire body() for > > >SetNextRule[methodName=addResource, > > >paramType=org.apache.catalina.deploy.ContextResource] > > >DEBUG 2006-12-19 22:08:11,593 [main] - Popping body text '' > > >DEBUG 2006-12-19 22:08:11,593 [main] - Fire end() for > > >SetNextRule[methodName=addResource, > > >paramType=org.apache.catalina.deploy.ContextResource] > > >DEBUG 2006-12-19 22:08:11,593 [main] - Fire end() for > > >ObjectCreateRule[className=org.apache.catalina.deploy.ContextResource, > > >attributeName=null] > > >DEBUG 2006-12-19 22:08:11,593 [main] - > > [ObjectCreateRule]{web-app/resource-ref} > > >Pop org.apache.catalina.deploy.ContextResource > > >DEBUG 2006-12-19 22:08:11,593 [main] - ignorableWhitespace( > > > > > >) > > >DEBUG 2006-12-19 22:08:11,594 [main] - endElement(,,web-app) > > >DEBUG 2006-12-19 22:08:11,594 [main] - match='web-app' > > >DEBUG 2006-12-19 22:08:11,594 [main] - bodyText='' > > >DEBUG 2006-12-19 22:08:11,594 [main] - Fire body() for > > >[EMAIL PROTECTED] > > >DEBUG 2006-12-19 22:08:11,594 [main] - Popping body text '' > > >DEBUG 2006-12-19 22:08:11,594 [main] - Fire end() for > > >[EMAIL PROTECTED] > > >DEBUG 2006-12-19 22:08:11,594 [main] - endDocument() > > >DEBUG 2006-12-19 22:08:11,628 [main] - Opening /dev/urandom > > >DEBUG 2006-12-19 22:08:11,628 [main] - Registering > > >Catalina:type=Manager,path=/ftrade/graph,host=localhost > > >DEBUG 2006-12-19 22:08:11,628 [main] - Force random number initialization > > >starting > > >DEBUG 2006-12-19 22:08:11,628 [main] - Getting message digest component > for > > >algorithm MD5 > > >DEBUG 2006-12-19 22:08:11,628 [main] - Completed getting message digest > > >component > > >DEBUG 2006-12-19 22:08:11,628 [main] - getDigest() 0 > > >DEBUG 2006-12-19 22:08:11,628 [main] - Force random number initialization > > >completed > > >DEBUG 2006-12-19 22:08:11,628 [main] - Start: Loading persisted sessions > > >DEBUG 2006-12-19 22:08:11,628 [main] - Loading persisted sessions from > > >SESSIONS.ser > > >DEBUG 2006-12-19 22:08:11,628 [main] - No persisted data file found > > >DEBUG 2006-12-19 22:08:11,628 [main] - Sending application start events > > >DEBUG 2006-12-19 22:08:11,628 [main] - Starting filters > > >DEBUG 2006-12-19 22:08:11,629 [main] - Parent class loader is: > > >WebappClassLoader > > >.. > > >.. > > > > > >--------------------------------------------------------------------- > > >To unsubscribe, e-mail: [EMAIL PROTECTED] > > >For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]