Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Logback: the reliable, generic, fast and flexible logging framework. Copyright (C) 1999-2011, QOS.ch. All rights reserved. This program and the accompanying materials are dual-licensed under either the terms of the Eclipse Public License v1.0 as published by the Eclipse Foundation or (per the licensee's choosing) under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation.
 
 package ch.qos.logback.classic.net;
 
 
 
 
 // Contributors: Moses Hohman <mmhohman@rainbow.uchicago.edu>
 
Read ch.qos.logback.classic.spi.ILoggingEvent objects sent from a remote client using Sockets (TCP). These logging events are logged according to local policy, as if they were generated locally.

For example, the socket node might decide to log events to a local file and also resent them to a second socket node.

Author(s):
Ceki Gülcü
Sébastien Pennec
Since:
0.8.4
 
 public class SocketNode implements Runnable {
 
   
   boolean closed = false;
   
   public SocketNode(SimpleSocketServer socketServerSocket socketLoggerContext context) {
     this. = socketServer;
     this. = socket;
     this. = context;
      = context.getLogger(SocketNode.class);
 
     try {
        = new ObjectInputStream(new BufferedInputStream(socket
           .getInputStream()));
     } catch (Exception e) {
       .error("Could not open ObjectInputStream to " + sockete);
     }
   }
 
   // public
   // void finalize() {
   // System.err.println("-------------------------Finalize called");
   // System.err.flush();
   // }
 
   public void run() {
     ILoggingEvent event;
     Logger remoteLogger;
 
     try {
       while (!) {
         // read an event from the wire
         event = (ILoggingEvent.readObject();
         // get a logger from the hierarchy. The name of the logger is taken to
         // be the name contained in the event.
         remoteLogger = .getLogger(event.getLoggerName());
         // apply the logger-level filter
         if (remoteLogger.isEnabledFor(event.getLevel())) {
           // finally log the event as if was generated locally
           remoteLogger.callAppenders(event);
         }
       }
     } catch (java.io.EOFException e) {
       .info("Caught java.io.EOFException closing connection.");
     } catch (java.net.SocketException e) {
       .info("Caught java.net.SocketException closing connection.");
     } catch (IOException e) {
       .info("Caught java.io.IOException: " + e);
       .info("Closing connection.");
     } catch (Exception e) {
      .error("Unexpected exception. Closing connection."e);
    }
    close();
  }
  
  void close() {
    if() {
      return;
    }
     = true;
    if ( != null) {
      try {
        .close();
      } catch (IOException e) {
        .warn("Could not close connection."e);
      } finally {
         = null;
      }
    }
  }
  
  public String toString() {
    return this.getClass().getName()+.toString();
  }
New to GrepCode? Check out our FAQ X