1 16 17 package org.apache.log4j.net; 18 19 import java.net.Socket ; 20 import java.io.IOException ; 21 import java.io.ObjectInputStream ; 22 import java.io.BufferedInputStream ; 23 24 25 import org.apache.log4j.*; 26 import org.apache.log4j.spi.*; 27 28 30 42 public class SocketNode implements Runnable { 43 44 Socket socket; 45 LoggerRepository hierarchy; 46 ObjectInputStream ois; 47 48 static Logger logger = Logger.getLogger(SocketNode.class); 49 50 public SocketNode(Socket socket, LoggerRepository hierarchy) { 51 this.socket = socket; 52 this.hierarchy = hierarchy; 53 try { 54 ois = new ObjectInputStream ( 55 new BufferedInputStream (socket.getInputStream())); 56 } 57 catch(Exception e) { 58 logger.error("Could not open ObjectInputStream to "+socket, e); 59 } 60 } 61 62 68 public void run() { 69 LoggingEvent event; 70 Logger remoteLogger; 71 72 try { 73 while(true) { 74 event = (LoggingEvent) ois.readObject(); 76 remoteLogger = hierarchy.getLogger(event.getLoggerName()); 78 if(event.getLevel().isGreaterOrEqual(remoteLogger.getEffectiveLevel())) { 81 remoteLogger.callAppenders(event); 83 } 84 } 85 } catch(java.io.EOFException e) { 86 logger.info("Caught java.io.EOFException closing conneciton."); 87 } catch(java.net.SocketException e) { 88 logger.info("Caught java.net.SocketException closing conneciton."); 89 } catch(IOException e) { 90 logger.info("Caught java.io.IOException: "+e); 91 logger.info("Closing connection."); 92 } catch(Exception e) { 93 logger.error("Unexpected exception. Closing conneciton.", e); 94 } 95 96 try { 97 ois.close(); 98 } catch(Exception e) { 99 logger.info("Could not close connection.", e); 100 } 101 } 102 } 103 | Popular Tags |