[logback-dev] svn commit: r1410 - in logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse: model views

noreply.seb at qos.ch noreply.seb at qos.ch
Wed Mar 7 14:53:45 CET 2007


Author: seb
Date: Wed Mar  7 14:53:45 2007
New Revision: 1410

Modified:
   logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/LoggingEventManager.java
   logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java

Log:
We now can change the pattern layout and re-fill the console with updated pattern

Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/LoggingEventManager.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/LoggingEventManager.java	(original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/LoggingEventManager.java	Wed Mar  7 14:53:45 2007
@@ -8,7 +8,6 @@
 import java.util.concurrent.TimeUnit;
 
 import ch.qos.logback.classic.spi.LoggingEvent;
-import ch.qos.logback.core.helpers.CyclicBuffer;
 
 /**
  * This class manages the logging events that are recieved by the plugin.
@@ -21,14 +20,16 @@
 
   private static LoggingEventManager manager;
   
-  private CyclicBuffer<LoggingEvent> cyclicBuffer;
+  private static final int MAX_SIZE = 100000;
+  private static final int MIN_SIZE = 50000;
+  private List<LoggingEvent> loggingEventList = new ArrayList<LoggingEvent>();
   private boolean sendingEvents = true;
   ScheduledExecutorService scheduledExecutorService;
 
   private List<LoggingEventManagerListener> listeners = new ArrayList<LoggingEventManagerListener>();
-
+  private int lastSentIndex;
+  
   private LoggingEventManager() {
-    cyclicBuffer = new CyclicBuffer<LoggingEvent>(5000);
   }
   
   public static LoggingEventManager getManager() {
@@ -37,23 +38,25 @@
     return manager;
   }
 
-  public static void shutdown() {
-    if (manager != null) {
-      manager = null;
-    }
-  }
-
   public void addLoggingEvent(LoggingEvent event) {
+    //trick to keep the original thread name
+    event.getThreadName();
+    loggingEventList.add(event);
+    listSizeCheck();
     if (sendingEvents) {
-      fireFavoritesChanged(new LoggingEvent[] { event }, NONE);
-    } else {
-      cyclicBuffer.add(event);
+      sendEvent(event);
     }
   }
+  
+  private void sendEvent(LoggingEvent event) {
+    fireFavoritesChanged(new LoggingEvent[] { event }, NONE);
+    lastSentIndex = loggingEventList.size()-1;
+  }
 
   /**
    * Listener management
    */
+  
   public void addLoggingEventManagerListener(LoggingEventManagerListener listener) {
     if (!listeners.contains(listener))
       listeners.add(listener);
@@ -71,17 +74,24 @@
     }
   }
   
+  /**
+   * Buffer management
+   */
+  
   public boolean isSendingEvents() {
     return sendingEvents;
   }
   
   public void toggleSendEvents() {
     sendingEvents = !sendingEvents;
-    emptyBuffer();
+    if (sendingEvents) {
+      emptyBuffer();
+    }
   }
   
   private void emptyBuffer() {
-    if (cyclicBuffer.length() == 0) {
+    if (lastSentIndex == loggingEventList.size()-1
+        || loggingEventList.isEmpty()) {
       return;
     }
     
@@ -89,14 +99,52 @@
     
     Runnable runnnable = new Runnable() {
 
+      int tmpIndex = lastSentIndex + 1;
+      
       public void run() {
-        LoggingEvent event = cyclicBuffer.get();
-        addLoggingEvent(event);
+        if (tmpIndex >= loggingEventList.size()) {
+          scheduledExecutorService.shutdownNow();
+        }
+        LoggingEvent event = loggingEventList.get(tmpIndex);
+        sendEvent(event);
+        tmpIndex++;
       }
     };
     
     scheduledExecutorService.scheduleAtFixedRate(runnnable,
         0, 1, TimeUnit.MILLISECONDS);
+  }
+  
+  private void listSizeCheck() {
+    if (loggingEventList.size() > MAX_SIZE) {
+      List sub = loggingEventList.subList(0, MIN_SIZE);
+      loggingEventList.removeAll(sub);
+    }
+  }
+  
+  public void reSendAllEvents() {
+    scheduledExecutorService = Executors.newScheduledThreadPool(2);
 
+    Runnable runnnable = new Runnable() {
+
+      int tmpIndex = 0;
+
+      public void run() {
+        if (tmpIndex >= loggingEventList.size()) {
+          scheduledExecutorService.shutdownNow();
+        }
+        LoggingEvent event = loggingEventList.get(tmpIndex);
+        sendEvent(event);
+        tmpIndex++;
+      }
+    };
+    
+    scheduledExecutorService.scheduleAtFixedRate(runnnable,
+        0, 1, TimeUnit.MILLISECONDS);
+  }
+  
+  public void clearEventList() {
+    loggingEventList.clear();
+    lastSentIndex = 0;
   }
 }

Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java	(original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java	Wed Mar  7 14:53:45 2007
@@ -101,6 +101,7 @@
       public void run() {
         super.run();
         myConsole.clearConsole();
+        LoggingEventManager.getManager().clearEventList();
       }
     };
     clearConsoleAction.setText("Clear console");
@@ -112,13 +113,12 @@
       @Override
       public void run() {
         super.run();
-        //provider.toggleAutoScroll();
         LoggingEventManager.getManager().toggleSendEvents();
         updateText();
       }
       
       private void updateText() {
-        if (/*provider.isAutoScroll()*/ LoggingEventManager.getManager().isSendingEvents()) {
+        if (LoggingEventManager.getManager().isSendingEvents()) {
           this.setText("Turn off auto scroll");
           this.setToolTipText("Turn off auto scroll");
         } else {
@@ -168,6 +168,8 @@
 
   public void updatePattern(String pattern) {
     labelProvider.updatePattern(pattern);
+    myConsole.clearConsole();
+    LoggingEventManager.getManager().reSendAllEvents();
   }
 
   public void updateConsoleHighWaterMark(int highWaterMark) {



More information about the logback-dev mailing list