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

noreply.seb at qos.ch noreply.seb at qos.ch
Tue Mar 27 19:51:12 CEST 2007


Author: seb
Date: Tue Mar 27 19:51:12 2007
New Revision: 1465

Modified:
   logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/actions/LogbackPreferencesAction.java
   logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/dialog/LogbackPreferencesDialog.java
   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/reciever/SimpleSocketServer.java
   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/LoggingEventContentProvider.java

Log:
Max number of events to store is now a preference.
The list of logging events is now synchronized.
The content provider now detects when the list has been stripped down and refreshes the whole viewer

Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/actions/LogbackPreferencesAction.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/actions/LogbackPreferencesAction.java	(original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/actions/LogbackPreferencesAction.java	Tue Mar 27 19:51:12 2007
@@ -7,6 +7,7 @@
 import org.eclipse.swt.widgets.Shell;
 
 import ch.qos.logback.eclipse.dialog.LogbackPreferencesDialog;
+import ch.qos.logback.eclipse.model.LoggingEventManager;
 import ch.qos.logback.eclipse.views.LogbackView;
 
 /**
@@ -46,6 +47,10 @@
     if (fontChanged(fd, dialog)) {
       view.updateFont(dialog.getFontName(), dialog.getFontSize());
     }
+    
+    if (dialog.getListMaxSize() != LoggingEventManager.getManager().getMaxSize()) {
+      LoggingEventManager.getManager().setMaxSize(dialog.getListMaxSize());
+    }
   }
   
   private boolean fontChanged(FontData[] fd, LogbackPreferencesDialog dialog) {

Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/dialog/LogbackPreferencesDialog.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/dialog/LogbackPreferencesDialog.java	(original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/dialog/LogbackPreferencesDialog.java	Tue Mar 27 19:51:12 2007
@@ -20,6 +20,8 @@
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Text;
 
+import ch.qos.logback.eclipse.model.LoggingEventManager;
+
 /**
  * A dialog that allows the user to change the pattern that is used to display
  * the logging events
@@ -32,11 +34,13 @@
   private int tmpServerPort = -1;
   private String fontName;
   private int fontSize;
+  private int listMaxSize;
 
   private Text patternField;
   private Text portField;
   private Combo fontCombo;
   private Text fontSizeField;
+  private Text maxSizeField;
 
   public LogbackPreferencesDialog(Shell parentShell, String namePattern, int serverPort, String fontName
       , int fontSize) {
@@ -45,6 +49,7 @@
     this.serverPort = serverPort;
     this.fontName = fontName;
     this.fontSize = fontSize;
+    this.listMaxSize = LoggingEventManager.getManager().getMaxSize();
 
     setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL);
   }
@@ -59,6 +64,7 @@
     createPatternUIParts(container);
     createServerPortUIParts(container);
     createFontUIParts(container);
+    createListSizeUIParts(container);
     
     initContent();
 
@@ -114,6 +120,15 @@
     fontSizeField = new Text(container, SWT.BORDER);
     fontSizeField.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
   }
+  
+  private void createListSizeUIParts(Composite container) {
+    final Label sizeLabel = new Label(container, SWT.None);
+    sizeLabel.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
+    sizeLabel.setText("Enter the maximum number of logs to display:");
+    
+    maxSizeField = new Text(container, SWT.BORDER);
+    maxSizeField.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
+  }
 
   private void initContent() {
     patternField.setText(pattern != null ? pattern : "");
@@ -143,6 +158,13 @@
         fontName = fontCombo.getItem(fontCombo.getSelectionIndex());
       }
     }); 
+    
+    maxSizeField.setText(String.valueOf(listMaxSize));
+    maxSizeField.addModifyListener(new ModifyListener() {
+      public void modifyText(ModifyEvent e) {
+        listMaxSize = Integer.parseInt(maxSizeField.getText());
+      }
+    });
   }
 
   protected void configureShell(Shell newShell) {
@@ -165,6 +187,10 @@
   public String getFontName() {
     return fontName;
   }
+  
+  public int getListMaxSize() {
+    return listMaxSize;
+  }
 
   @Override
   protected void okPressed() {

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	Tue Mar 27 19:51:12 2007
@@ -1,9 +1,11 @@
 package ch.qos.logback.eclipse.model;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
-import java.util.concurrent.ScheduledExecutorService;
+
+import org.eclipse.ui.IMemento;
 
 import ch.qos.logback.classic.spi.LoggingEvent;
 
@@ -13,16 +15,18 @@
  * @author Sébastien Pennec
  */
 public class LoggingEventManager {
-
+  
+  private static final String TAG_MGR = "manager";
+  private static final String TAG_MAXSIZE = "maxSize";
+  private static final double REMOVE_RATIO = 0.33;
+  
   static LoggingEvent[] NONE = new LoggingEvent[] {};
-
+  
   private static LoggingEventManager manager;
   
-  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 int maxSize = 20000;
+  private int removeQuantity = 14000;
+  private List<LoggingEvent> loggingEventList = Collections.synchronizedList(new ArrayList<LoggingEvent>());
 
   private List<LoggingEventManagerListener> listeners = new ArrayList<LoggingEventManagerListener>();
   
@@ -41,9 +45,7 @@
     }
     loggingEventList.add(event);
     listSizeCheck();
-    if (sendingEvents) {
-      sendEvent(event);
-    }
+    sendEvent(event);
   }
   
   private void sendEvent(LoggingEvent event) {
@@ -68,9 +70,11 @@
   }
   
   private void listSizeCheck() {
-    if (loggingEventList.size() > MAX_SIZE) {
-      List sub = loggingEventList.subList(0, MIN_SIZE);
-      loggingEventList.removeAll(sub);
+    synchronized(loggingEventList) {
+      if (loggingEventList.size() > maxSize) {
+        List sub = loggingEventList.subList(0, removeQuantity);
+        sub.clear();
+      }
     }
   }
   
@@ -79,10 +83,12 @@
   }
   
   public LoggingEvent getEvent(int index) {
-    if (index > loggingEventList.size()-1) {
-      return null;
+    synchronized(loggingEventList) {
+      if (index > loggingEventList.size()-1) {
+        return null;
+      }
+      return loggingEventList.get(index);
     }
-    return loggingEventList.get(index);
   }
   
   public int getEventCount() {
@@ -92,4 +98,32 @@
   public int getIndex(LoggingEvent event) {
     return loggingEventList.indexOf(event);
   }
+
+  public int getMaxSize() {
+    return maxSize;
+  }
+
+  public void setMaxSize(int maxSize) {
+    this.maxSize = maxSize;
+    Double dbl = maxSize * REMOVE_RATIO;
+    this.removeQuantity = dbl.intValue();
+    listSizeCheck();
+  }
+
+  public void saveState(IMemento memento) {
+    IMemento mem = memento.createChild(TAG_MGR);
+    mem.putInteger(TAG_MAXSIZE, maxSize);
+  }
+  
+  public void init(IMemento memento) {
+    IMemento mem = memento.getChild(TAG_MGR);
+    if (mem == null) {
+      return;
+    }
+    
+    Integer max = mem.getInteger(TAG_MAXSIZE);
+    if (max != null) {
+      this.maxSize = max;
+    }
+  }
 }

Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/reciever/SimpleSocketServer.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/reciever/SimpleSocketServer.java	(original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/reciever/SimpleSocketServer.java	Tue Mar 27 19:51:12 2007
@@ -3,7 +3,6 @@
 import java.io.IOException;
 import java.net.ServerSocket;
 import java.net.Socket;
-import java.net.UnknownHostException;
 
 import org.eclipse.ui.IMemento;
 

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	Tue Mar 27 19:51:12 2007
@@ -242,6 +242,7 @@
     EventFilter.saveState(memento);
     labelProvider.saveState(memento);
     server.saveState(memento);
+    LoggingEventManager.getManager().saveState(memento);
     IMemento mem = memento.createChild(TAG_DISPLAY);
     FontData[] fd = viewer.getTable().getFont().getFontData();
     mem.putString(TAG_FONTNAME, fd[0].getName());
@@ -261,7 +262,7 @@
       tmpFontSize = mem.getInteger(TAG_FONTSIZE);
       tmpFontName = mem.getString(TAG_FONTNAME);
     }
-
+    LoggingEventManager.getManager().init(memento);
   }
 
   public Viewer getViewer() {

Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventContentProvider.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventContentProvider.java	(original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventContentProvider.java	Tue Mar 27 19:51:12 2007
@@ -20,6 +20,7 @@
 
   private TableViewer viewer;
   private boolean autoScroll = true;
+  private int lastCount = 0;
 
   public LoggingEventContentProvider(TableViewer viewer) {
     this.viewer = viewer;
@@ -41,9 +42,14 @@
   }
 
   private void updateViewer(final LoggingEventManagerEvent event) {
-    // we should *not* add an element to the viewer here!
     int count = LoggingEventManager.getManager().getEventCount();
     viewer.setItemCount(count);
+    if (count < lastCount) {
+      //we've stripped down the list, we
+      //need to refresh the whole viewer
+      viewer.refresh();
+    }
+    lastCount = count;
     if (event.getItemsAdded().length > 0 && autoScroll) {
       viewer.getTable().showItem(viewer.getTable().getItem(count - 1));
     }
@@ -71,6 +77,8 @@
 
   public void updateElement(int index) {
     LoggingEvent event = LoggingEventManager.getManager().getEvent(index); 
-    viewer.replace(event, index);
+    if (event != null) {
+      viewer.replace(event, index);
+    }
   }
 }



More information about the logback-dev mailing list