tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Will Hartung" <wi...@msoft.com>
Subject Re: Setting up logging - Log4j
Date Wed, 12 Feb 2003 00:47:39 GMT
Log 4J isn't overly difficult.

Here's some tips:

Create a log4j.properties file. Here's a sample:
-----
# Set root category priority to DEBUG and its only appender to A1.
log4j.rootCategory=DEBUG, A1

# Print only messages of priority INFO or above in the class
your.app.ClassName
log4j.category.your.app.ClassName=INFO

# 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=%-8r %-5p %c - %m%n
-----

Ensure that your log4j.properties file is in your classpath. For a WebApp,
you should put it into WEB-INF/classes.

To use the logger, here's a sample simple class:
package your.app;

import org.apache.log4j.Category;

public class ClassName
{
    /** The log4j Category for this class */
    private static final Category log =
Category.getInstance(ClassName.class.getName());

    public void doSomething() {
        log.debug("Look, I'm doing something!");
    }
}

The two components, the log4j.properties file, and the log.debug line are
the keys to basic Log4J functionality. log4j.properties tells what to log,
and where to log it. The log.debug tells at what level you want a particular
message to be logged.

Log4J has a lot more than this, but these two simple bits will take you a
log way.

Regards,

Will Hartung
(willh@msoft.com)




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message