JULog - Getting started

main | news | status | download | faq | gettingStarted | javadoc

Getting prerequisites and building the JULog library.

You'll need some prerequisite software:

When everything is done, open a command prompt in the JULog directory, and type  

ant jar

to create the JULog library JAR file.

Basic concepts

The central concept of the JUlog is a logger. You tipically request a logger on a per-class basis using the static method in LoggerFactory:

public class MyClass {
    private static final Logger logger = LoggerFactory.getInstance(MyClass.class);
    ...
}

Then, whenever you have something to log, just call a method with appropriate severity, passing it a message and an optional throwable to log:

    int num = getDefaultValue();
    try
{    
        num = Integer.parseInt(numstr);
    } catch (NumberParseException e) {
        logger.warn("Could not parse " + numstr + ". Using default value " + num, e);
    }


If you want to avoid the cost of constructing the message when a specific logging  level is not enabled, you use one of isXxxEnabled methods:

    boolean debug = logger.isDebugEnabled();
    long t = debug ? System.currentTimeMillis() : 0L;
    ... (do the operations whose execution time is measured) ...
    if(debug) {
        t = System.currentTimeMillis() - t;
        debug.log("The operation took " +  t + "ms to complete");
    }

Note that you don't really care what happens with the log messages.You're just using whatever logging JUlog library discovered in the classpath. It is the responsibility of the person who assembles or administers the application to configure the logging properly - your code is just a library integrated into the application that only uses the logging if it is available, but does not control it in any way.


(c) Attila Szegedi, 2002. All rights reserved.

 This project is hosted on SourceForge.SourceForge Logo