1 package org.apache.avalon.excalibur.logger.factory; 2 3 import java.io.IOException ; 4 import java.net.InetAddress ; 5 import java.net.UnknownHostException ; 6 7 import org.apache.log.LogTarget; 8 import org.apache.log.output.net.SocketOutputTarget; 9 import org.apache.avalon.framework.configuration.Configuration; 10 import org.apache.avalon.framework.configuration.ConfigurationException; 11 12 37 public class SocketTargetFactory extends AbstractTargetFactory 38 { 39 40 47 public LogTarget createTarget( final Configuration conf ) 48 throws ConfigurationException 49 { 50 final InetAddress address; 51 52 final Configuration configChild = conf.getChild( "address", false ); 53 if ( null == configChild ) 54 { 55 throw new ConfigurationException( "target address not specified in the config" ); 56 } 57 58 try 59 { 60 address = InetAddress.getByName( configChild.getAttribute( "hostname" ) ); 61 } 62 catch ( UnknownHostException uhex ) 63 { 64 throw new ConfigurationException( "Host specified in socket target adress is unknown!", uhex ); 65 } 66 67 final int port = configChild.getAttributeAsInteger( "port" ); 68 69 try 70 { 71 return new SocketOutputTarget( address, port ); 72 } 73 catch ( final IOException ioex ) 74 { 75 throw new ConfigurationException( "Failed to create target!", ioex.fillInStackTrace() ); 76 } 77 } 78 } 79 | Popular Tags |