I don't recall what the BasicConfigurator does. You are making an assumption
that it creates a Console appender and sets this on the root logger. Don't
make assumptions. Don't configure anything manually. Just put
log4j.properties in WEB-INF/classes and point your File Appender to some other
file than what Tomcat logs to and see if you get the output you expect. If you
don't try this, there's nothing else I can do to help.
Jake
Quoting [EMAIL PROTECTED]:
> I just used the basic configurator which should just log to catalina.out,
> right?
> But still nothing gets logged (I do get a warning about No appenders could be
> found) Here is the code:
>
> public class TestServlet extends HttpServlet {
> private static Logger logger;
>
> public TestServlet() {
> BasicConfigurator.configure();
> logger =
> Logger.getLogger(GenerateChartServlet.class.getName());
>
> }
>
> private void doPost(HttpServletRequest req, HttpServletResponse res)
> throws IOException, ServletException
> {
> ...
> // This never gets outputted to log file
> logger.debug("TestServlet: debug");
> logger.warn("TestServlet: warn");
> logger.info("TestServlet: info");
> ...
> }
> }
>
> #
> # Output from catalina.out
> #
> Dec 20, 2006 2:51:42 PM org.apache.catalina.core.AprLifecycleListener
> lifecycleEvent
> INFO: The Apache Tomcat Native library which allows optimal performance in
> Dec 20, 2006 2:51:42 PM org.apache.coyote.http11.Http11BaseProtocol init
> INFO: Initializing Coyote HTTP/1.1 on http-80
> Dec 20, 2006 2:51:42 PM org.apache.catalina.startup.Catalina load
> INFO: Initialization processed in 2102 ms
> Dec 20, 2006 2:51:43 PM org.apache.catalina.core.StandardService start
> INFO: Starting service Catalina
> Dec 20, 2006 2:51:43 PM org.apache.catalina.core.StandardEngine start
> INFO: Starting Servlet Engine: Apache Tomcat/5.5.20
> Dec 20, 2006 2:51:43 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.
> Dec 20, 2006 2:51: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 2:51:46 PM org.apache.catalina.core.ApplicationContext log
> INFO: ContextListener: contextInitialized()
> Dec 20, 2006 2:51:46 PM org.apache.catalina.core.ApplicationContext log
> INFO: SessionListener: contextInitialized()
> Dec 20, 2006 2:51:47 PM org.apache.catalina.core.ApplicationContext log
> INFO: ContextListener: contextInitialized()
> Dec 20, 2006 2:51:47 PM org.apache.catalina.core.ApplicationContext log
> INFO: SessionListener: contextInitialized()
> Dec 20, 2006 2:51:47 PM org.apache.coyote.http11.Http11BaseProtocol start
> INFO: Starting Coyote HTTP/1.1 on http-80
> Dec 20, 2006 2:51:47 PM org.apache.jk.common.ChannelSocket init
> INFO: JK: ajp13 listening on /0.0.0.0:8009
> Dec 20, 2006 2:51:47 PM org.apache.jk.server.JkMain start
> INFO: Jk running ID=0 time=0/27 config=null
> Dec 20, 2006 2:51:47 PM org.apache.catalina.storeconfig.StoreLoader load
> INFO: Find registry server-registry.xml at classpath resource
> Dec 20, 2006 2:51:47 PM org.apache.catalina.startup.Catalina start
> INFO: Server startup in 4841 ms
>
> Quoting James Stauffer <[EMAIL PROTECTED]>:
>
> > Add -log4j.debug to the command to start Tomcat (CATALINA_OPTS). That
> > will cause log4j to print to standard out info about the config and
> > will tell you if log4j finds the config file, etc.
> > Also, ar you sure that your servlet finds everything? I would add
> > system output to it to make sure that everything happens as thought.
> >
> > On 12/20/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > > 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]
> > >
> > >
> >
> >
> > --
> > James Stauffer http://www.geocities.com/stauffer_james/
> > Are you good? Take the test at http://www.livingwaters.com/good/
> >
> > ---------------------------------------------------------------------
> > 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]