/*
 * Copyright (C) The Apache Software Foundation. All rights reserved.
 *
 * This software is published under the terms of the Apache Software
 * License version 1.1, a copy of which has been included with this
 * distribution in the LICENSE.txt file.  */
package org.apache.log4j.chainsaw;

import java.io.EOFException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggingEvent;

/**
 * A daemon thread the processes connections from a
 * <code>org.apache.log4j.net.SocketAppender.html</code>.
 *
 * @author <a href="mailto:oliver@puppycrawl.com">Oliver Burn</a>
 */
class LoggingReceiver extends Thread {
    /** used to log messages **/
    private static final Logger logger = Logger.getLogger(LoggingReceiver.class);

    /**
     * Helper that actually processes a client connection. It receives events
     * and adds them to the supplied model.
     *
     * @author <a href="mailto:oliver@puppycrawl.com">Oliver Burn</a>
     */
    private class Slurper implements Runnable {
        /** socket connection to read events from **/
        private final Socket mClient;

        /**
         * Creates a new <code>Slurper</code> instance.
         *
         * @param aClient socket to receive events from
         */
        Slurper(Socket aClient) {
            mClient = aClient;
        }

        /** loops getting the events **/
        public void run() {
            logger.debug("Starting to get data");
            try {
                final ObjectInputStream ois =
                    new ObjectInputStream(mClient.getInputStream());
                while (true) {
                    final LoggingEvent event = (LoggingEvent) ois.readObject();
                    mModel.addEvent(new EventDetails(event));
                }
            } catch (EOFException e) {
                logger.info("Reached EOF, closing connection");
            } catch (SocketException e) {
                logger.info("Caught SocketException, closing connection");
            } catch (IOException e) {
                logger.warn("Got IOException, closing connection", e);
            } catch (ClassNotFoundException e) {
                logger.warn("Got ClassNotFoundException, closing connection", e);
            }

            try {
                mClient.close();
            } catch (IOException e) {
                logger.warn("Error closing connection", e);
            }
        }
    }

    /** where to put the events **/
    private final MyTableModel mModel;

    /** server for listening for connections **/
    private final ServerSocket mSvrSock;

    /**
     * Creates a new <code>LoggingReceiver</code> instance.
     *
     * @param aModel model to place put received into
     * @param aPort port to listen on
     * @throws IOException if an error occurs
     */
    LoggingReceiver(MyTableModel aModel, int aPort) throws IOException {
        setDaemon(true);
        mModel = aModel;
        mSvrSock = new ServerSocket(aPort);
    }

    /** Listens for client connections **/
    public void run() {
        logger.info("Thread started");
        try {
            while (true) {
                logger.debug("Waiting for a connection");
                final Socket client = mSvrSock.accept();
                logger.debug("Got a connection from " +
                          client.getInetAddress().getHostName());
                final Thread t = new Thread(new Slurper(client));
                t.setDaemon(true);
                t.start();
            }
        } catch (IOException e) {
            logger.error("Error in accepting connections, stopping.", e);
        }
    }
}

@@ -831,22 +831,19 @@
  Logger 
-logger
+LOG
  = Logge
@@ -1531,38 +1531,35 @@
 ) %7B%0A            
-logger
+LOG
 .debug(%22Starting
@@ -1949,30 +1949,27 @@
             
-logger
+LOG
 .info(%22Reach
@@ -2052,30 +2052,27 @@
             
-logger
+LOG
 .info(%22Caugh
@@ -2158,38 +2158,35 @@
                 
-logger
+LOG
 .warn(%22Got IOExc
@@ -2279,30 +2279,27 @@
             
-logger
+LOG
 .warn(%22Got C
@@ -2466,22 +2466,19 @@
         
-logger
+LOG
 .warn(%22E
@@ -3175,22 +3175,19 @@
         
-logger
+LOG
 .info(%22T
@@ -3252,38 +3252,35 @@
                 
-logger
+LOG
 .debug(%22Waiting 
@@ -3372,22 +3372,19 @@
         
-logger
+LOG
 .debug(%22
@@ -3667,14 +3667,11 @@
     
-logger
+LOG
 .err

Change made on the mainline that should be on the branch as well.