[logback-dev] svn commit: r874 - logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net

noreply.seb at qos.ch noreply.seb at qos.ch
Mon Nov 6 17:42:55 CET 2006


Author: seb
Date: Mon Nov  6 17:42:54 2006
New Revision: 874

Modified:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SimpleSocketServer.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SocketAppender.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SocketNode.java

Log:
Added an option to the SocketAppender to call the getCallerData method on logging events before serializing them so that
the caller data is available on the remote machine.
Minor fix to SimpleSocketServer.java
Reformat only on SocketNode.java

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SimpleSocketServer.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SimpleSocketServer.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SimpleSocketServer.java	Mon Nov  6 17:42:54 2006
@@ -18,6 +18,7 @@
 import ch.qos.logback.classic.LoggerContext;
 import ch.qos.logback.classic.joran.JoranConfigurator;
 import ch.qos.logback.core.joran.spi.JoranException;
+import ch.qos.logback.core.util.StatusPrinter;
 
 /**
  * A simple {@link SocketNode} based server.
@@ -92,8 +93,10 @@
     if (configFile.endsWith(".xml")) {
       LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
       JoranConfigurator configurator = new JoranConfigurator();
+      lc.reset();
       configurator.setContext(lc);
       configurator.doConfigure(configFile);
+      StatusPrinter.print(lc);
     }
   }
 }

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SocketAppender.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SocketAppender.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SocketAppender.java	Mon Nov  6 17:42:54 2006
@@ -119,6 +119,7 @@
   int port = DEFAULT_PORT;
   ObjectOutputStream oos;
   int reconnectionDelay = DEFAULT_RECONNECTION_DELAY;
+  boolean includeCallerData = false;
 
   private Connector connector;
 
@@ -248,6 +249,9 @@
 
     if (oos != null) {
       try {
+        if (includeCallerData) {
+          ((LoggingEvent)event).getCallerData();
+        }
         oos.writeObject(event);
         // addInfo("=========Flushing.");
         oos.flush();
@@ -317,6 +321,11 @@
   public int getPort() {
     return port;
   }
+  
+  public void setIncludeCallerData(boolean includeCallerData) {
+    this.includeCallerData = includeCallerData;
+  }
+  
 
   /**
    * The <b>ReconnectionDelay</b> option takes a positive integer representing

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SocketNode.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SocketNode.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SocketNode.java	Mon Nov  6 17:42:54 2006
@@ -39,61 +39,61 @@
  */
 public class SocketNode implements Runnable {
 
-	Socket socket;
-	LoggerContext context;
-	ObjectInputStream ois;
-
-	static Logger logger = (Logger) LoggerFactory.getLogger(SocketNode.class);
-
-	public SocketNode(Socket socket, LoggerContext context) {
-		this.socket = socket;
-		this.context = context;
-		try {
-			ois = new ObjectInputStream(new BufferedInputStream(socket
-					.getInputStream()));
-		} catch (Exception e) {
-			logger.error("Could not open ObjectInputStream to " + socket, e);
-		}
-	}
-
-	// public
-	// void finalize() {
-	// System.err.println("-------------------------Finalize called");
-	// System.err.flush();
-	// }
-
-	public void run() {
-		LoggingEvent event;
-		Logger remoteLogger;
-
-		try {
-			while (true) {
-				// read an event from the wire
-				event = (LoggingEvent) ois.readObject();
-				// get a logger from the hierarchy. The name of the logger is taken to
-				// be the name contained in the event.
-				remoteLogger = context.getLogger(event.getLoggerRemoteView().getName());
-				// 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) {
-			logger.info("Caught java.io.EOFException closing connection.");
-		} catch (java.net.SocketException e) {
-			logger.info("Caught java.net.SocketException closing connection.");
-		} catch (IOException e) {
-			logger.info("Caught java.io.IOException: " + e);
-			logger.info("Closing connection.");
-		} catch (Exception e) {
-			logger.error("Unexpected exception. Closing connection.", e);
-		}
-
-		try {
-			ois.close();
-		} catch (Exception e) {
-			logger.info("Could not close connection.", e);
-		}
-	}
+  Socket socket;
+  LoggerContext context;
+  ObjectInputStream ois;
+
+  static Logger logger = (Logger) LoggerFactory.getLogger(SocketNode.class);
+
+  public SocketNode(Socket socket, LoggerContext context) {
+    this.socket = socket;
+    this.context = context;
+    try {
+      ois = new ObjectInputStream(new BufferedInputStream(socket
+          .getInputStream()));
+    } catch (Exception e) {
+      logger.error("Could not open ObjectInputStream to " + socket, e);
+    }
+  }
+
+  // public
+  // void finalize() {
+  // System.err.println("-------------------------Finalize called");
+  // System.err.flush();
+  // }
+
+  public void run() {
+    LoggingEvent event;
+    Logger remoteLogger;
+
+    try {
+      while (true) {
+        // read an event from the wire
+        event = (LoggingEvent) ois.readObject();
+        // get a logger from the hierarchy. The name of the logger is taken to
+        // be the name contained in the event.
+        remoteLogger = context.getLogger(event.getLoggerRemoteView().getName());
+        // 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) {
+      logger.info("Caught java.io.EOFException closing connection.");
+    } catch (java.net.SocketException e) {
+      logger.info("Caught java.net.SocketException closing connection.");
+    } catch (IOException e) {
+      logger.info("Caught java.io.IOException: " + e);
+      logger.info("Closing connection.");
+    } catch (Exception e) {
+      logger.error("Unexpected exception. Closing connection.", e);
+    }
+
+    try {
+      ois.close();
+    } catch (Exception e) {
+      logger.info("Could not close connection.", e);
+    }
+  }
 }



More information about the logback-dev mailing list