ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jon Stevens <...@latchkey.com>
Subject Re: [Vote] Logging
Date Wed, 09 May 2001 06:51:01 GMT
on 5/8/01 11:26 PM, "Conor MacNeill" <conor@cortexebusiness.com.au> wrote:

> In the .antrc file (or .antrc.xml), we should use introspection to configure
> user preferred listeners/loggers.

Ewwww....No! That is what interfaces are for.

Guys, this stuff isn't difficult.

Here is a stripped down example of what I'm talking about taken from
Velocity...

<http://jakarta.apache.org/cvsweb/index.cgi/jakarta-velocity/src/java/org/ap
ache/velocity/runtime/log/>


public interface LogSystem
{
    public void logMessage(int level, String message);
}

public class LogKitLogSystem implements LogSystem
{
    public void init()
    {
        // do setup and config stuff here.
    }

   /**
     *  logs messages
     *
     *  @param level severity level
     *  @param message complete error message
     */
    public void logMessage(int level, String message)
    {
        switch (level)
        {
            case LogSystem.WARN_ID:
                logger.warn( message );
                break;
            case LogSystem.INFO_ID:
                logger.info(message);
                break;
            case LogSystem.DEBUG_ID:
                logger.debug(message);
                break;
            case LogSystem.ERROR_ID:
                logger.error(message);
                break;
            default:
                logger.info(message);
                break;
        }
    }
}

public class Log4JLogSystem implements LogSystem
{
    // similar to LogKitSystem, but for Log4J
}

public class LogManager
{
    
    public static LogSystem createLogSystem()
    {
        // create a LogKitSystem or Log4JLogSystem
        LogSystem instance = Class.forName ().newInstance
        instance.init();
    }
}

Now, in Ant, you use LogManager to get an instance of the class you want and
you are done. You can then write a static little wrapper around logMessage
to do something like Log.debug() or hell, put it in the interface!

Why is this so difficult for everyone to comprehend and why does Peter think
that this is re-implementation of stuff??

-jon

-- 
If you come from a Perl or PHP background, JSP is a way to take
your pain to new levels. --Anonymous
<http://jakarta.apache.org/velocity/ymtd/ymtd.html>


Mime
View raw message