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]