1 17 18 package org.apache.avalon.logging.logkit; 19 20 import org.apache.avalon.framework.configuration.Configuration; 21 22 import org.apache.avalon.util.i18n.ResourceManager; 23 import org.apache.avalon.util.i18n.Resources; 24 25 import org.apache.log.format.ExtendedPatternFormatter; 26 import org.apache.log.format.Formatter; 27 import org.apache.log.format.PatternFormatter; 28 import org.apache.log.format.RawFormatter; 29 import org.apache.log.format.SyslogFormatter; 30 import org.apache.log.format.XMLFormatter; 31 32 35 public class DefaultFormatterFactory implements FormatterFactory 36 { 37 41 private static final Resources REZ = 42 ResourceManager.getPackageResources( DefaultFormatterFactory.class ); 43 44 48 54 public Formatter createFormatter( final Configuration config ) 55 { 56 if( null == config ) return new StandardFormatter( DEFAULT_FORMAT ); 57 final String type = config.getAttribute( "type", "pattern" ); 58 final String format = config.getValue( DEFAULT_FORMAT ); 59 return createFormatter( type, format ); 60 } 61 62 69 public Formatter createFormatter( String type, String format ) 70 { 71 if( "avalon".equals( type ) ) 72 { 73 return new StandardFormatter( format, true ); 74 } 75 else if( "console".equals( type ) ) 76 { 77 return new StandardFormatter( format, false ); 78 } 79 else if( "extended".equals( type ) ) 80 { 81 89 return new ExtendedPatternFormatter( format, 1 ); 90 } 91 else if( "raw".equals( type ) ) 92 { 93 return new RawFormatter(); 94 } 95 else if( "xml".equals( type ) ) 96 { 97 return new XMLFormatter(); 98 } 99 else if( "syslog".equals( type ) ) 100 { 101 return new SyslogFormatter(); 102 } 103 else if( "pattern".equals( type ) ) 104 { 105 return new PatternFormatter( format ); 106 } 107 else 108 { 109 final String error = 110 REZ.getString( "formatter.error.unknown-type", type ); 111 throw new IllegalArgumentException ( error ); 112 } 113 } 114 } 115 | Popular Tags |