1 17 18 package org.apache.avalon.logging.logkit.factory; 19 20 import java.io.OutputStream ; 21 22 import org.apache.avalon.framework.configuration.Configuration; 23 import org.apache.avalon.framework.configuration.ConfigurationException; 24 25 import org.apache.avalon.logging.logkit.LogTargetFactory; 26 import org.apache.avalon.logging.logkit.FormatterFactory; 27 28 import org.apache.log.LogTarget; 29 import org.apache.log.format.Formatter; 30 import org.apache.log.output.io.StreamTarget; 31 32 55 public class StreamTargetFactory implements LogTargetFactory 56 { 57 61 private final FormatterFactory m_formatter; 62 63 67 public StreamTargetFactory( FormatterFactory formatter ) 68 { 69 m_formatter = formatter; 70 } 71 72 76 79 public LogTarget createTarget( final Configuration configuration ) 80 { 81 OutputStream stream; 82 83 final Configuration streamConfig = 84 configuration.getChild( "name", false ); 85 if( null == streamConfig ) 86 { 87 stream = System.out; 88 } 89 else 90 { 91 final String streamName = streamConfig.getValue( "" ); 92 if( streamName.equals( "System.out" ) ) 93 { 94 stream = System.out; 95 } 96 else 97 { 98 stream = System.err; 99 } 100 } 101 102 Configuration formatConfig = configuration.getChild( "format", false ); 103 final Formatter formatter = 104 m_formatter.createFormatter( formatConfig ); 105 106 return new StreamTarget( stream, formatter ); 107 } 108 } 109 110 | Popular Tags |