1 17 18 package org.apache.avalon.logging.impl; 19 20 import org.apache.avalon.framework.logger.Logger; 21 22 import org.apache.avalon.util.criteria.Parameter; 23 import org.apache.avalon.util.criteria.CriteriaException; 24 25 import org.apache.avalon.util.i18n.ResourceManager; 26 import org.apache.avalon.util.i18n.Resources; 27 28 35 public class LoggerParameter extends Parameter 36 { 37 41 private static final Resources REZ = 42 ResourceManager.getPackageResources( LoggerParameter.class ); 43 44 private static final int PRIORITY = ConsoleLogger.LEVEL_WARN; 45 46 50 58 public LoggerParameter( final String key, final Logger logger ) 59 { 60 super( key, Logger.class, logger ); 61 } 62 63 68 public Object resolve( Object value ) 69 throws CriteriaException 70 { 71 if( value == null ) 72 { 73 return new ConsoleLogger( PRIORITY ); 74 } 75 if( value instanceof Logger ) 76 { 77 return value; 78 } 79 if( value instanceof String ) 80 { 81 String priority = ((String )value).toLowerCase(); 82 if( priority.equals( "debug" ) ) 83 { 84 return new ConsoleLogger( ConsoleLogger.LEVEL_DEBUG ); 85 } 86 else if( priority.equals( "info" ) ) 87 { 88 return new ConsoleLogger( ConsoleLogger.LEVEL_INFO ); 89 } 90 else if( priority.equals( "warn" ) ) 91 { 92 return new ConsoleLogger( ConsoleLogger.LEVEL_WARN ); 93 } 94 else if( priority.equals( "error" ) ) 95 { 96 return new ConsoleLogger( ConsoleLogger.LEVEL_ERROR ); 97 } 98 else if( priority.equals( "fatal" ) ) 99 { 100 return new ConsoleLogger( ConsoleLogger.LEVEL_FATAL ); 101 } 102 else if( priority.equals( "none" ) ) 103 { 104 return new ConsoleLogger( ConsoleLogger.LEVEL_DISABLED ); 105 } 106 } 107 final String error = 108 REZ.getString( 109 "parameter.unknown", 110 value.getClass().getName(), Logger.class.getName() ); 111 throw new CriteriaException( error ); 112 } 113 } 114 | Popular Tags |