November 11, 2008

Using Log4J category to create specialized log files

Most Java Developers have used Log4J at some point or another...

I like most use it everyday to output messages from my application to log files on disk. One thing i been doing a lot is taken these log lines and outputting them into a specialized log file.

An example of that is cerating a WebTrackingLogger calls where i have a log method as follows

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class WebTrackingLogger {

    private static final Log log = LogFactory.getLog(WebTrackingLogger.class);

    public static void log(Sting ip, String url, String.... otherValues) { + " " + URL);
       log.warn(IP + " " + URL, e);

Now for me to isolate the logs from this Logger class into a new file i add the following to my

# Daily Rolling File appender for WebTrackingLogger, PL
log4j.appender.PL.layout.ConversionPattern=%d %x - %m%n

and that is it...

No comments:

Post a Comment