From 73e215e5193cbbeb05d181e309bd650355e5cbf4 Mon Sep 17 00:00:00 2001 From: Peter Donald Date: Sun, 13 Jan 2002 04:50:48 +0000 Subject: [PATCH] Refactor log() to level into LogLevel class. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270727 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/java/org/apache/antlib/core/Log.java | 21 +------ .../java/org/apache/antlib/core/LogLevel.java | 63 ++++++++++++++++++- 2 files changed, 63 insertions(+), 21 deletions(-) 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. *