[logback-dev] svn commit: r1347 - logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views
noreply.seb at qos.ch
noreply.seb at qos.ch
Thu Feb 22 17:22:53 CET 2007
Author: seb
Date: Thu Feb 22 17:22:52 2007
New Revision: 1347
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/LoggingEventContentProvider.java
Log:
re-using already created streams
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 Thu Feb 22 17:22:52 2007
@@ -45,10 +45,9 @@
viewer = new TextConsoleViewer(parent, myConsole);
viewer.setEditable(false);
- provider = new LoggingEventContentProvider();
+ provider = new LoggingEventContentProvider(myConsole);
labelProvider = new LoggingEventLabelProvider();
provider.setLabelProvider(labelProvider);
- provider.setConsole(myConsole);
LoggingEventManager.getManager().addLoggingEventManagerListener(provider);
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 Thu Feb 22 17:22:52 2007
@@ -10,6 +10,7 @@
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.eclipse.PluginLogger;
import ch.qos.logback.eclipse.model.LoggingEventManagerEvent;
import ch.qos.logback.eclipse.model.LoggingEventManagerListener;
@@ -20,18 +21,34 @@
*/
public class LoggingEventContentProvider implements LoggingEventManagerListener {
- private MessageConsole console;
+ private MessageConsoleStream redStream;
+ private MessageConsoleStream blackStream;
+ private int count = 0;
+ private static int MAX_COUNT = 1000;
private Color cachedRed;
+ private Color cachedBlack;
private LabelProvider labelProvider;
- public LoggingEventContentProvider() {
+ public LoggingEventContentProvider(MessageConsole console) {
Display display = Display.getCurrent();
cachedRed = new Color(display, 255, 0,0);
+ cachedBlack = new Color(display, 0, 0,0);
+ redStream = console.newMessageStream();
+ redStream.setColor(cachedRed);
+ blackStream = console.newMessageStream();
+ blackStream.setColor(cachedBlack);
}
public void dispose() {
cachedRed.dispose();
+ cachedBlack.dispose();
+ try {
+ redStream.close();
+ blackStream.close();
+ } catch (Exception e) {
+ PluginLogger.logError(e);
+ }
}
public void loggingEventsChanged(final LoggingEventManagerEvent event) {
@@ -52,23 +69,28 @@
private void updateViewer(final LoggingEventManagerEvent event) {
LoggingEvent le = (LoggingEvent) event.getItemsAdded()[0];
- MessageConsoleStream stream = console.newMessageStream();
if (le.getLevel().isGreaterOrEqual(Level.WARN)) {
- stream.setColor(cachedRed);
+ redStream.println(labelProvider.getText(le));
+ } else {
+ blackStream.println(labelProvider.getText(le));
}
- stream.println(labelProvider.getText(le));
+ count ++;
+ if (count > MAX_COUNT) {
+ flushStreams();
+ }
+
+ }
+
+ private void flushStreams() {
try {
- stream.close();
- } catch (IOException e) {
- //do nothing for now
+ blackStream.flush();
+ redStream.flush();
+ } catch (Exception e) {
+ PluginLogger.logError(e);
}
}
public void setLabelProvider(LabelProvider provider) {
this.labelProvider = provider;
}
-
- public void setConsole(MessageConsole console) {
- this.console = console;
- }
}
More information about the logback-dev
mailing list