You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by do...@apache.org on 2002/05/24 06:02:02 UTC
cvs commit: jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework LogUtil.java LogLevel.java
donaldp 02/05/23 21:02:02
Modified: antlib/src/java/org/apache/antlib/core Log.java
Resources.properties
Added: antlib/src/java/org/apache/antlib/core
StringToLogLevelConverter.java
api/src/java/org/apache/myrmidon/api/event LogLevel.java
framework/src/java/org/apache/myrmidon/framework
LogUtil.java
Removed: framework/src/java/org/apache/myrmidon/framework
LogLevel.java
Log:
Move LogLevel into api.event package. This is the lesser of two evils.
Revision Changes Path
1.3 +3 -2 jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/core/Log.java
Index: Log.java
===================================================================
RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/core/Log.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Log.java 12 May 2002 04:03:32 -0000 1.2
+++ Log.java 24 May 2002 04:02:02 -0000 1.3
@@ -9,7 +9,8 @@
import org.apache.myrmidon.api.AbstractTask;
import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.framework.LogLevel;
+import org.apache.myrmidon.api.event.LogLevel;
+import org.apache.myrmidon.framework.LogUtil;
/**
* This is a task used to log messages in the build file.
@@ -64,7 +65,7 @@
public void execute()
throws TaskException
{
- LogLevel.log( getContext(), m_level, getMessage() );
+ LogUtil.log( getContext(), m_level, getMessage() );
}
/**
1.5 +1 -4 jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/core/Resources.properties
Index: Resources.properties
===================================================================
RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/core/Resources.properties,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Resources.properties 15 May 2002 10:11:54 -0000 1.4
+++ Resources.properties 24 May 2002 04:02:02 -0000 1.5
@@ -7,11 +7,8 @@
loadprop.file.notice=Loading properties from "{0}".
loadprop.missing-file.notice=Unable to find property file "{0}".
-convert.bad-boolean.error=Error converting object ({0}) to Boolean.
-convert.bad-byte.error=Error converting object ({0}) to Byte.
-convert.bad-class.error=Error converting object ({0}) to Class.
-convert.bad-double.error=Error converting object ({0}) to Double.
convert.bad-file.error=Error converting object ({0}) to File.
+convert.bad-level.error=String "{0}" is not a valid LogLevel.
getByName.error=Failed to retrieve enum by calling getByName on "{0}". (Reason: {1}).
enum.missing.getByName.error=Enum class "{0}" is missing a public static method named "getByName" that accepts a single string parameter.
1.1 jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/core/StringToLogLevelConverter.java
Index: StringToLogLevelConverter.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.antlib.core;
import org.apache.aut.converter.AbstractConverter;
import org.apache.aut.converter.ConverterException;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.api.event.LogLevel;
/**
* String to LogLevel converter
*
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
* @ant.converter source="java.lang.String" destination="org.apache.myrmidon.api.event.LogLevel"
*/
public class StringToLogLevelConverter
extends AbstractConverter
{
private static final Resources REZ =
ResourceManager.getPackageResources( StringToLogLevelConverter.class );
public StringToLogLevelConverter()
{
super( String.class, LogLevel.class );
}
public Object convert( final Object object, final Object context )
throws ConverterException
{
final LogLevel logLevel = LogLevel.getByName( (String)object );
if( null != logLevel )
{
return logLevel;
}
else
{
final String message =
REZ.getString( "convert.bad-level.error",
object );
throw new ConverterException( message );
}
}
}
1.1 jakarta-ant-myrmidon/api/src/java/org/apache/myrmidon/api/event/LogLevel.java
Index: LogLevel.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.api.event;
import java.util.HashMap;
import java.util.Set;
import java.util.Collection;
/**
* Type safe Enum for Log Levels and utility method
* for using enum to write to logger.
*
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/05/24 04:02:02 $
*/
public final class LogLevel
{
//Map for all the levels
private static final HashMap c_levels = new HashMap();
//standard enums for version of JVM
public static final LogLevel ERROR = new LogLevel( "error" );
public static final LogLevel WARN = new LogLevel( "warn" );
public static final LogLevel INFO = new LogLevel( "info" );
public static final LogLevel VERBOSE = new LogLevel( "verbose" );
public static final LogLevel DEBUG = new LogLevel( "debug" );
/**
* String name of LogLevel.
*/
private final String m_name;
/**
* Retrieve the log level for the specified name.
*
* @param name the name of the LogLevel object to retrieve
* @returns The LogLevel for specified name or null
*/
public static LogLevel getByName( final String name )
{
return (LogLevel)c_levels.get( name );
}
/**
* Retrieve the names of all the LogLevels.
*
* @returns The names of all the LogLevels
*/
public static String[] getLevelNames()
{
final Set keys = c_levels.keySet();
return (String[])keys.toArray( new String[ keys.size() ] );
}
/**
* Retrieve sll of the LogLevels.
*
* @returns All of the LogLevels
*/
public static LogLevel[] getLevels()
{
final Collection collection = c_levels.values();
final LogLevel[] results = new LogLevel[ collection.size() ];
return (LogLevel[])collection.toArray( results );
}
/**
* Private constructor so no instance except here can be defined.
*
* @param name the name of Log Level
*/
private LogLevel( final String name )
{
m_name = name;
c_levels.put( name, this );
}
/**
* Retrieve the name of this Enum item, set in the constructor.
* @return the name <code>String</code> of this Enum item
*/
public final String getName()
{
return m_name;
}
/**
* Human readable description of this Enum item. For use when debugging.
* @return String in the form <code>type[name]</code>, eg.:
* <code>Color[Red]</code>.
*/
public String toString()
{
return getClass().getName() + "[" + m_name + "]";
}
}
1.1 jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/LogUtil.java
Index: LogUtil.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.framework;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.event.LogLevel;
/**
* Type safe Enum for Log Levels and utility method
* for using enum to write to logger.
*
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/05/24 04:02:02 $
*/
public final class LogUtil
{
/**
* Private Constructor to block instantiation.
*/
private LogUtil()
{
}
/**
* Log a message.
*
* @param level the level to write the log message at.
* @param message the message to write.
*/
public static void log( final TaskContext context,
final LogLevel level,
final String message )
{
if( LogLevel.ERROR == level )
{
context.error( message );
}
else if( LogLevel.WARN == level )
{
context.warn( message );
}
else if( LogLevel.INFO == level )
{
context.info( message );
}
else if( LogLevel.VERBOSE == level )
{
context.verbose( message );
}
else
{
context.debug( message );
}
}
/**
* Log a message.
*
* @param level the level to write the log message at.
* @param message the message to write.
* @param throwable the throwable.
*/
public static void log( final TaskContext context,
final LogLevel level,
final String message,
final Throwable throwable )
{
if( LogLevel.ERROR == level )
{
context.error( message, throwable );
}
else if( LogLevel.WARN == level )
{
context.warn( message, throwable );
}
else if( LogLevel.INFO == level )
{
context.info( message, throwable );
}
else if( LogLevel.VERBOSE == level )
{
context.verbose( message, throwable );
}
else
{
context.debug( message, throwable );
}
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>