logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From psm...@apache.org
Subject svn commit: r634545 - in /logging/log4j/trunk/src: changes/changes.xml main/java/org/apache/log4j/net/SocketHubAppender.java
Date Fri, 07 Mar 2008 05:44:34 GMT
Author: psmith
Date: Thu Mar  6 21:44:32 2008
New Revision: 634545

URL: http://svn.apache.org/viewvc?rev=634545&view=rev
Log:
Bug 44551 SocketHubAppender in the 1.2.16 does not support a scroll back buffer or application
property.

This returns a feature from the old 1.3 codebase (yay!)

Applied patch generously  provided by Jason Tholstrup.

Modified:
    logging/log4j/trunk/src/changes/changes.xml
    logging/log4j/trunk/src/main/java/org/apache/log4j/net/SocketHubAppender.java

Modified: logging/log4j/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/changes/changes.xml?rev=634545&r1=634544&r2=634545&view=diff
==============================================================================
--- logging/log4j/trunk/src/changes/changes.xml (original)
+++ logging/log4j/trunk/src/changes/changes.xml Thu Mar  6 21:44:32 2008
@@ -36,6 +36,7 @@
        <action action="fix" issue="43387">Minor documentation changes.</action>
        <action action="fix" issue="43304">Make javamail, jmx, jms dependencies optional
in pom.xml.</action>
        <action action="add" issue="43874">SocketHubAppender should expose actual port
in use to extending classes.</action>
+       <action action="add" issue="44551">SocketHubAppender in the 1.2.16 does not
support a scroll back buffer or application property</action>
     </release>
   
     <release version="1.2.15" date="2007-08-24" description="SyslogAppender enhancements,
NTEventLogAppender and Maven build.">

Modified: logging/log4j/trunk/src/main/java/org/apache/log4j/net/SocketHubAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/main/java/org/apache/log4j/net/SocketHubAppender.java?rev=634545&r1=634544&r2=634545&view=diff
==============================================================================
--- logging/log4j/trunk/src/main/java/org/apache/log4j/net/SocketHubAppender.java (original)
+++ logging/log4j/trunk/src/main/java/org/apache/log4j/net/SocketHubAppender.java Thu Mar
 6 21:44:32 2008
@@ -26,6 +26,7 @@
 import java.io.InterruptedIOException;
 import java.net.InetAddress;
 
+import org.apache.log4j.helpers.CyclicBuffer;
 import org.apache.log4j.helpers.LogLog;
 import org.apache.log4j.spi.LoggingEvent;
 import org.apache.log4j.AppenderSkeleton;
@@ -114,6 +115,8 @@
   private Vector oosList = new Vector();
   private ServerMonitor serverMonitor = null;
   private boolean locationInfo = false;
+  private CyclicBuffer buffer = null;
+  private String application;
   
   public SocketHubAppender() { }
 
@@ -179,14 +182,23 @@
     Append an event to all of current connections. */
   public
   void append(LoggingEvent event) {
-	// if no event or no open connections, exit now
-    if(event == null || oosList.size() == 0)
-      return;
+    if (event != null) {
+      // set up location info if requested
+      if (locationInfo) {
+        event.getLocationInformation();
+      }
+      if (application != null) {
+          event.setProperty("application", application);
+        } 
+      if (buffer != null) {
+        buffer.add(event);
+      }
+    }
 
-    // set up location info if requested
-    if (locationInfo) {
-    	event.getLocationInformation();	
-    } 
+    // if no event or no open connections, exit now
+    if ((event == null) || (oosList.size() == 0)) {
+      return;
+    }
 
 	// loop through the current set of open connections, appending the event to each
     for (int streamCount = 0; streamCount < oosList.size(); streamCount++) {    	
@@ -238,6 +250,23 @@
   public
   void setPort(int _port) {
     port = _port;
+	}
+
+  /**
+   * The <b>App</b> option takes a string value which should be the name of the
application getting logged. If property was already set (via system
+   * property), don't set here.
+   */
+  public 
+  void setApplication(String lapp) {
+    this.application = lapp;
+  }
+
+  /**
+   * Returns value of the <b>Application</b> option.
+   */
+  public 
+  String getApplication() {
+    return application;
   }
   
   /**
@@ -246,6 +275,27 @@
   int getPort() {
     return port;
   }
+
+  /**
+   * The <b>BufferSize</b> option takes a positive integer representing the number
of events this appender will buffer and send to newly connected
+   * clients.
+   */
+  public 
+  void setBufferSize(int _bufferSize) {
+    buffer = new CyclicBuffer(_bufferSize);
+  }
+
+  /**
+   * Returns value of the <b>bufferSize</b> option.
+   */
+  public 
+  int getBufferSize() {
+    if (buffer == null) {
+      return 0;
+    } else {
+      return buffer.getMaxSize();
+    }
+  }
   
   /**
      The <b>LocationInfo</b> option takes a boolean value. If true,
@@ -325,6 +375,17 @@
       }
     }
     
+    private 
+    void sendCachedEvents(ObjectOutputStream stream) throws IOException {
+      if (buffer != null) {
+        for (int i = 0; i < buffer.length(); i++) {
+          stream.writeObject(buffer.get(i));
+        }
+        stream.flush();
+        stream.reset();
+      }
+    }
+
     /**
       Method that runs, monitoring the ServerSocket and adding connections as
       they connect to the socket. */
@@ -375,11 +436,13 @@
 	        	
               // create an ObjectOutputStream
               ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
+              if (buffer != null && buffer.length() > 0) {
+                sendCachedEvents(oos);
+              }
 	            
               // add it to the oosList.  OK since Vector is synchronized.
               oosList.addElement(oos);
-            }
-            catch (IOException e) {
+            } catch (IOException e) {
               LogLog.error("exception creating output stream on socket.", e);
             }
           }



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message