Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2011-09-19 08:19:32 +0000
committerEike Stepper2011-09-19 08:19:32 +0000
commit6aaf02ce1ef0dc713a8bd7b99b71fc90a4192485 (patch)
treed3a78e142738ebdadd181460a5877ad44eafb681 /plugins
parent5429686a393775048194827da329c3de9a77db6d (diff)
downloadcdo-6aaf02ce1ef0dc713a8bd7b99b71fc90a4192485.tar.gz
cdo-6aaf02ce1ef0dc713a8bd7b99b71fc90a4192485.tar.xz
cdo-6aaf02ce1ef0dc713a8bd7b99b71fc90a4192485.zip
[358069] Provide log event filtering hook
https://bugs.eclipse.org/bugs/show_bug.cgi?id=358069
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractPlatform.java76
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMPlatform.java11
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/log/OMLogFilter.java31
3 files changed, 104 insertions, 14 deletions
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractPlatform.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractPlatform.java
index f093326cc0..5e57d1a322 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractPlatform.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractPlatform.java
@@ -16,6 +16,7 @@ import org.eclipse.net4j.util.io.IORuntimeException;
import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.net4j.util.om.OMBundle;
import org.eclipse.net4j.util.om.OMPlatform;
+import org.eclipse.net4j.util.om.log.OMLogFilter;
import org.eclipse.net4j.util.om.log.OMLogHandler;
import org.eclipse.net4j.util.om.log.OMLogger;
import org.eclipse.net4j.util.om.log.OMLogger.Level;
@@ -50,6 +51,8 @@ public abstract class AbstractPlatform implements OMPlatform
private Map<String, AbstractBundle> bundles = new ConcurrentHashMap<String, AbstractBundle>(0);
+ private Queue<OMLogFilter> logFilters = new ConcurrentLinkedQueue<OMLogFilter>();
+
private Queue<OMLogHandler> logHandlers = new ConcurrentLinkedQueue<OMLogHandler>();
private Queue<OMTraceHandler> traceHandlers = new ConcurrentLinkedQueue<OMTraceHandler>();
@@ -72,6 +75,19 @@ public abstract class AbstractPlatform implements OMPlatform
return bundle;
}
+ public void addLogFilter(OMLogFilter logFilter)
+ {
+ if (!logFilters.contains(logFilter))
+ {
+ logFilters.add(logFilter);
+ }
+ }
+
+ public void removeLogFilter(OMLogFilter logFilter)
+ {
+ logFilters.remove(logFilter);
+ }
+
public void addLogHandler(OMLogHandler logHandler)
{
if (!logHandlers.contains(logHandler))
@@ -224,17 +240,46 @@ public abstract class AbstractPlatform implements OMPlatform
public void log(OMLogger logger, Level level, String msg, Throwable t)
{
- for (OMLogHandler logHandler : logHandlers)
+ if (!logFilters.isEmpty())
{
- try
+ for (OMLogFilter logFilter : logFilters)
{
- logHandler.logged(logger, level, msg, t);
+ try
+ {
+ if (logFilter.filter(logger, level, msg, t))
+ {
+ if (TRACER().isEnabled())
+ {
+ TRACER().format("Filtered log event: logger={0}, level={1}, msg={2}\n{3}", logger, level, msg, t);
+ }
+
+ return;
+ }
+ }
+ catch (Exception ex)
+ {
+ if (TRACER().isEnabled())
+ {
+ TRACER().trace(ex);
+ }
+ }
}
- catch (Exception ex)
+ }
+
+ if (!logHandlers.isEmpty())
+ {
+ for (OMLogHandler logHandler : logHandlers)
{
- if (TRACER().isEnabled())
+ try
+ {
+ logHandler.logged(logger, level, msg, t);
+ }
+ catch (Exception ex)
{
- TRACER().trace(ex);
+ if (TRACER().isEnabled())
+ {
+ TRACER().trace(ex);
+ }
}
}
}
@@ -242,17 +287,20 @@ public abstract class AbstractPlatform implements OMPlatform
public void trace(OMTraceHandlerEvent event)
{
- for (OMTraceHandler traceHandler : traceHandlers)
+ if (!traceHandlers.isEmpty())
{
- try
- {
- traceHandler.traced(event);
- }
- catch (Exception ex)
+ for (OMTraceHandler traceHandler : traceHandlers)
{
- if (TRACER().isEnabled())
+ try
+ {
+ traceHandler.traced(event);
+ }
+ catch (Exception ex)
{
- TRACER().trace(ex);
+ if (TRACER().isEnabled())
+ {
+ TRACER().trace(ex);
+ }
}
}
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMPlatform.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMPlatform.java
index d1fa873197..6f3efc5fef 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMPlatform.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMPlatform.java
@@ -11,6 +11,7 @@
package org.eclipse.net4j.util.om;
import org.eclipse.net4j.internal.util.bundle.AbstractPlatform;
+import org.eclipse.net4j.util.om.log.OMLogFilter;
import org.eclipse.net4j.util.om.log.OMLogHandler;
import org.eclipse.net4j.util.om.trace.OMTraceHandler;
@@ -48,6 +49,16 @@ public interface OMPlatform
public void setDebugging(boolean debugging);
+ /**
+ * @since 3.2
+ */
+ public void addLogFilter(OMLogFilter logFilter);
+
+ /**
+ * @since 3.2
+ */
+ public void removeLogFilter(OMLogFilter logFilter);
+
public void addLogHandler(OMLogHandler logHandler);
public void removeLogHandler(OMLogHandler logHandler);
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/log/OMLogFilter.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/log/OMLogFilter.java
new file mode 100644
index 0000000000..d9d902fa20
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/log/OMLogFilter.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.om.log;
+
+import org.eclipse.net4j.util.om.OMPlatform;
+import org.eclipse.net4j.util.om.log.OMLogger.Level;
+
+/**
+ * Filters log events before they are being passed to {@link OMPlatform#addLogFilter(OMLogFilter) registered}
+ * {@link OMLogHandler log handlers}.
+ *
+ * @author Eike Stepper
+ * @since 3.2
+ */
+public interface OMLogFilter
+{
+ /**
+ * Prevents the log event represented by the arguments from being passed to
+ * {@link OMPlatform#addLogFilter(OMLogFilter) registered} {@link OMLogHandler log handlers}, if and only if
+ * <code>true</code> is returned.
+ */
+ public boolean filter(OMLogger logger, Level level, String msg, Throwable t);
+}

Back to the top