1 17 package org.apache.log.output.net; 18 19 import java.io.IOException ; 20 import java.io.ObjectOutputStream ; 21 import java.net.InetAddress ; 22 import java.net.Socket ; 23 import org.apache.log.LogEvent; 24 import org.apache.log.output.AbstractOutputTarget; 25 26 33 public class SocketOutputTarget extends AbstractOutputTarget 34 { 35 36 37 private Socket m_socket; 38 39 40 private ObjectOutputStream m_outputStream; 41 42 49 public SocketOutputTarget( final InetAddress address, 50 final int port ) 51 throws IOException 52 { 53 m_socket = new Socket ( address, port ); 54 m_outputStream = new ObjectOutputStream ( m_socket.getOutputStream() ); 55 super.open(); 56 } 57 58 65 public SocketOutputTarget( final String host, 66 final int port ) 67 throws IOException 68 { 69 m_socket = new Socket ( host, port ); 70 m_outputStream = new ObjectOutputStream ( m_socket.getOutputStream() ); 71 super.open(); 72 } 73 74 80 protected void write( LogEvent event ) 81 { 82 try 83 { 84 m_outputStream.writeObject( event ); 85 } 86 catch( final IOException ioex ) 87 { 88 getErrorHandler().error( "Error writting to socket", ioex, null ); 89 } 90 } 91 92 97 protected void doProcessEvent( LogEvent event ) 98 { 99 write( event ); 100 } 101 102 106 public synchronized void close() 107 { 108 super.close(); 109 m_socket = null; 110 } 111 } 112 | Popular Tags |