[logback-dev] svn commit: r1381 - in logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse: dialog model views
noreply.seb at qos.ch
noreply.seb at qos.ch
Fri Mar 2 15:37:15 CET 2007
Author: seb
Date: Fri Mar 2 15:37:15 2007
New Revision: 1381
Modified:
logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/dialog/LogbackFilterDialog.java
logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/EventFilter.java
logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/FilterContentProvider.java
logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventContentProvider.java
Log:
Updated EvaluatorFilter editor.
Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/dialog/LogbackFilterDialog.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/dialog/LogbackFilterDialog.java (original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/dialog/LogbackFilterDialog.java Fri Mar 2 15:37:15 2007
@@ -2,7 +2,6 @@
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
@@ -62,8 +61,6 @@
editComposite.setSize(1000, 1000);
createEditionUIPart(editComposite);
- //initContent();
-
return container;
}
@@ -182,6 +179,9 @@
current = (EvaluatorFilter)element;
JaninoEventEvaluator eval = (JaninoEventEvaluator)current.getEvaluator();
expressionField.setText(eval.getExpression());
+ matchField.setText(current.getOnMatch().toString());
+ mismatchField.setText(current.getOnMismatch().toString());
+
}
private void saveCurrentFilter() {
@@ -190,6 +190,8 @@
eval.stop();
String oldExp = eval.getExpression();
eval.setExpression(expressionField.getText());
+ current.setOnMatch(matchField.getText());
+ current.setOnMismatch(mismatchField.getText());
eval.start();
if (!eval.isStarted()) {
eval.stop();
@@ -197,6 +199,7 @@
eval.start();
MessageDialog.openInformation(getShell(), "Logback View", ERROR_MESSAGE_EXPRESSION);
}
+ current.start();
EventFilter.add(current);
emptyEditionUI();
}
@@ -222,7 +225,6 @@
current.stop();
JaninoEventEvaluator eval = (JaninoEventEvaluator) current.getEvaluator();
eval.stop();
- EventFilter.remove(current);
FilterContentProvider.getProvider().remove(current);
emptyEditionUI();
}
Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/EventFilter.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/EventFilter.java (original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/EventFilter.java Fri Mar 2 15:37:15 2007
@@ -1,6 +1,7 @@
package ch.qos.logback.eclipse.model;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import ch.qos.logback.classic.boolex.JaninoEventEvaluator;
@@ -8,6 +9,7 @@
import ch.qos.logback.core.Context;
import ch.qos.logback.core.ContextBase;
import ch.qos.logback.core.filter.EvaluatorFilter;
+import ch.qos.logback.core.spi.FilterReply;
public class EventFilter {
@@ -15,8 +17,6 @@
private static List<EvaluatorFilter> filterList = new ArrayList<EvaluatorFilter>();
- private static EvaluatorFilter first;
-
static {
{
EvaluatorFilter filter = new EvaluatorFilter();
@@ -49,6 +49,22 @@
}
public static boolean filter(LoggingEvent event) {
+ if (filterList.isEmpty()) {
+ return true;
+ }
+
+ Iterator<EvaluatorFilter> it = filterList.iterator();
+ EvaluatorFilter filter;
+ while (it.hasNext()) {
+ filter = it.next();
+ FilterReply reply = filter.decide(event);
+ if(reply == FilterReply.DENY) {
+ return false;
+ } else if (reply == FilterReply.ACCEPT) {
+ return true;
+ }
+ }
+
return true;
}
@@ -67,7 +83,7 @@
}
public static void remove(EvaluatorFilter filter) {
- if (!filterList.contains(filter)) {
+ if (filterList.contains(filter)) {
filterList.remove(filter);
}
}
Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/FilterContentProvider.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/FilterContentProvider.java (original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/FilterContentProvider.java Fri Mar 2 15:37:15 2007
@@ -46,9 +46,9 @@
case 0:
return eval.getExpression();
case 1:
- return "onMatch";
+ return filter.getOnMatch().toString();
case 2:
- return "onMismatch";
+ return filter.getOnMismatch().toString();
}
return null;
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 Fri Mar 2 15:37:15 2007
@@ -14,7 +14,9 @@
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.core.helpers.CyclicBuffer;
import ch.qos.logback.eclipse.PluginLogger;
+import ch.qos.logback.eclipse.model.EventFilter;
import ch.qos.logback.eclipse.model.LoggingEventManagerEvent;
import ch.qos.logback.eclipse.model.LoggingEventManagerListener;
@@ -28,18 +30,21 @@
private MessageConsoleStream redStream;
private MessageConsoleStream blackStream;
private TextConsoleViewer viewer;
-
+
+ private CyclicBuffer<LoggingEvent> cyclicBuffer;
+
private Color cachedRed;
private Color cachedBlack;
private LabelProvider labelProvider;
-
- private boolean autoScroll;
+
+ private boolean autoScroll = true;
public LoggingEventContentProvider(MessageConsole console, TextConsoleViewer viewer) {
Display display = Display.getCurrent();
cachedRed = new Color(display, 255, 0, 0);
cachedBlack = new Color(display, 0, 0, 0);
this.viewer = viewer;
+ this.cyclicBuffer = new CyclicBuffer<LoggingEvent>(4000);
redStream = console.newMessageStream();
redStream.setColor(cachedRed);
@@ -47,7 +52,7 @@
blackStream.setColor(cachedBlack);
}
- WorkbenchJob revealJob = new WorkbenchJob("Reveal End of Document") {//$NON-NLS-1$
+ WorkbenchJob revealJob = new WorkbenchJob("Reveal End of Document") {
public IStatus runInUIThread(IProgressMonitor monitor) {
StyledText textWidget = viewer.getTextWidget();
if (textWidget != null) {
@@ -70,18 +75,22 @@
}
public void loggingEventsChanged(final LoggingEventManagerEvent event) {
- updateViewer(event);
+
+ if (autoScroll) {
+ updateViewer(event);
+ } else {
+ LoggingEvent le = (LoggingEvent) event.getItemsAdded()[0];
+ cyclicBuffer.add(le);
+ }
}
private void updateViewer(final LoggingEventManagerEvent event) {
LoggingEvent le = (LoggingEvent) event.getItemsAdded()[0];
try {
flushStreams();
- if (le.getLevel().isGreaterOrEqual(Level.WARN)) {
- redStream.println(labelProvider.getText(le));
- } else {
- blackStream.println(labelProvider.getText(le));
- }
+
+ writeEvent(le);
+
} catch (Exception e) {
PluginLogger.logError(e);
}
@@ -99,19 +108,67 @@
}
}
+ public void emptyCyclicBuffer() {
+
+ int max = 100;
+
+ int i = 0;
+
+ LoggingEvent le = (LoggingEvent) cyclicBuffer.get();
+ while (le != null) {
+ if (i++ >= max) {
+ try {
+ if (i % 100 == 0) {
+// IOConsolePartitioner idp = (IOConsolePartitioner)redStream.getConsole().getDocument().getDocumentPartitioner();
+// idp.clearBuffer();
+ System.out.println("100 more done: " + i);
+ }
+ } catch (Exception e) {
+
+ }
+ }
+
+ writeEvent(le);
+
+ le = (LoggingEvent) cyclicBuffer.get();
+ }
+ }
+
+ private void writeEvent(LoggingEvent le) {
+ if (!EventFilter.filter(le)) {
+ return;
+ }
+
+ if (le.getLevel().isGreaterOrEqual(Level.WARN)) {
+ redStream.println(labelProvider.getText(le));
+ } else {
+ blackStream.println(labelProvider.getText(le));
+ }
+ }
+
public void setLabelProvider(LabelProvider provider) {
this.labelProvider = provider;
}
-
+
public void setAutoScroll(boolean autoScroll) {
this.autoScroll = autoScroll;
}
-
+
public boolean isAutoScroll() {
return autoScroll;
}
-
+
public void toggleAutoScroll() {
autoScroll = !autoScroll;
+
+ if (!autoScroll) {
+ // if autoScroll is turned off
+ // we clear the buffer first.
+ cyclicBuffer.clear();
+ } else {
+ // if it is turned on
+ // we empty the buffer
+ emptyCyclicBuffer();
+ }
}
}
More information about the logback-dev
mailing list