diff --git a/proposal/myrmidon/src/java/org/apache/antlib/core/Log.java b/proposal/myrmidon/src/java/org/apache/antlib/core/Log.java index 19419fc37..14c19fc9e 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/core/Log.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/core/Log.java @@ -63,26 +63,7 @@ public class Log public void execute() throws TaskException { - if( LogLevel.FATAL_ERROR == m_level ) - { - getLogger().fatalError( m_message ); - } - else if( LogLevel.ERROR == m_level ) - { - getLogger().error( m_message ); - } - else if( LogLevel.WARN == m_level ) - { - getLogger().warn( m_message ); - } - else if( LogLevel.INFO == m_level ) - { - getLogger().info( m_message ); - } - else - { - getLogger().debug( m_message ); - } + LogLevel.log( getLogger(), m_message, m_level ); } /** diff --git a/proposal/myrmidon/src/java/org/apache/antlib/core/LogLevel.java b/proposal/myrmidon/src/java/org/apache/antlib/core/LogLevel.java index 30096ea30..aa78db89d 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/core/LogLevel.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/core/LogLevel.java @@ -10,9 +10,11 @@ package org.apache.antlib.core; import java.util.HashMap; import java.util.Set; import org.apache.avalon.framework.Enum; +import org.apache.avalon.framework.logger.Logger; /** - * Type safe Enum for Log Levels. + * Type safe Enum for Log Levels and utility method + * for using enum to write to logger. * * @author Peter Donald */ @@ -51,6 +53,65 @@ public final class LogLevel return (String[])keys.toArray( new String[ keys.size() ] ); } + /** + * Log a message to the Logger at the specified level. + */ + public static void log( final Logger logger, + final String message, + final LogLevel level ) + { + if( LogLevel.FATAL_ERROR == level ) + { + logger.fatalError( message ); + } + else if( LogLevel.ERROR == level ) + { + logger.error( message ); + } + else if( LogLevel.WARN == level ) + { + logger.warn( message ); + } + else if( LogLevel.INFO == level ) + { + logger.info( message ); + } + else + { + logger.debug( message ); + } + } + + /** + * Log a message to the Logger at the specified level. + */ + public static void log( final Logger logger, + final String message, + final Throwable throwable, + final LogLevel level ) + { + if( LogLevel.FATAL_ERROR == level ) + { + logger.fatalError( message, throwable ); + } + else if( LogLevel.ERROR == level ) + { + logger.error( message, throwable ); + } + else if( LogLevel.WARN == level ) + { + logger.warn( message, throwable ); + } + else if( LogLevel.INFO == level ) + { + logger.info( message, throwable ); + } + else + { + logger.debug( message, throwable ); + } + } + /** * Private constructor so no instance except here can be defined. *