Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.equinox.common.tests/src/org/eclipse/equinox/common/tests/PlatformLogWriterTest.java110
-rw-r--r--bundles/org.eclipse.equinox.common.tests/src/org/eclipse/equinox/common/tests/RuntimeTests.java3
-rw-r--r--bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/PlatformLogWriter.java12
3 files changed, 119 insertions, 6 deletions
diff --git a/bundles/org.eclipse.equinox.common.tests/src/org/eclipse/equinox/common/tests/PlatformLogWriterTest.java b/bundles/org.eclipse.equinox.common.tests/src/org/eclipse/equinox/common/tests/PlatformLogWriterTest.java
new file mode 100644
index 000000000..f2d4b4f15
--- /dev/null
+++ b/bundles/org.eclipse.equinox.common.tests/src/org/eclipse/equinox/common/tests/PlatformLogWriterTest.java
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ * Copyright (c) 2019 IBM Corporation and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.common.tests;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.eclipse.core.internal.runtime.RuntimeLog;
+import org.eclipse.core.runtime.ILogListener;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.tests.harness.CoreTest;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.service.log.LogService;
+import org.osgi.service.log.Logger;
+
+public class PlatformLogWriterTest extends CoreTest {
+
+ public static class TestILogListener implements ILogListener {
+ final AtomicReference<CountDownLatch> expected = new AtomicReference<>();
+ final List<IStatus> statuses = new CopyOnWriteArrayList<>();
+ @Override
+ public void logging(IStatus status, String plugin) {
+ CountDownLatch current = expected.get();
+ if (current != null) {
+ current.countDown();
+ }
+ statuses.add(status);
+ }
+ List<IStatus> getAllExpectedStatus() throws InterruptedException {
+ CountDownLatch current = expected.get();
+ if (current != null) {
+ current.await(10, TimeUnit.SECONDS);
+ }
+ return new ArrayList<>(statuses);
+ }
+
+ void setExpected(int expected) {
+ statuses.clear();
+ this.expected.set(new CountDownLatch(expected));
+ }
+ }
+
+ public PlatformLogWriterTest() {
+ super(null);
+ }
+
+ public PlatformLogWriterTest(String name) {
+ super(name);
+ }
+
+ LogService logService;
+ final TestILogListener listener = new TestILogListener();
+
+
+ @Override
+ protected void setUp() {
+ Bundle thisBundle = FrameworkUtil.getBundle(getClass());
+ BundleContext context = thisBundle.getBundleContext();
+ logService = context.getService(context.getServiceReference(LogService.class));
+ RuntimeLog.addLogListener(listener);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ RuntimeLog.removeLogListener(listener);
+ }
+
+ public void testLogServiceLevels() throws InterruptedException {
+ listener.setExpected(6);
+ Logger logger = logService.getLogger("org.eclipse.equinox.logger");
+ logger.audit("audit");
+ logger.error("error");
+ logger.warn("warn");
+ logger.info("info");
+ logger.debug("debug");
+ logger.trace("trace");
+ List<IStatus> allStatus = listener.getAllExpectedStatus();
+ assertEquals("Wrong number of status.", 6, allStatus.size());
+ assertStatus(allStatus.get(0), "audit", IStatus.OK);
+ assertStatus(allStatus.get(1), "error", IStatus.ERROR);
+ assertStatus(allStatus.get(2), "warn", IStatus.WARNING);
+ assertStatus(allStatus.get(3), "info", IStatus.INFO);
+ assertStatus(allStatus.get(4), "debug", IStatus.OK);
+ assertStatus(allStatus.get(5), "trace", IStatus.OK);
+
+
+ }
+
+ private void assertStatus(IStatus status, String message, int severity) {
+ assertEquals("Wrong message.", message, status.getMessage());
+ assertEquals("Wrong severity.", severity, status.getSeverity());
+ }
+}
diff --git a/bundles/org.eclipse.equinox.common.tests/src/org/eclipse/equinox/common/tests/RuntimeTests.java b/bundles/org.eclipse.equinox.common.tests/src/org/eclipse/equinox/common/tests/RuntimeTests.java
index 89ceee98d..e07eded3e 100644
--- a/bundles/org.eclipse.equinox.common.tests/src/org/eclipse/equinox/common/tests/RuntimeTests.java
+++ b/bundles/org.eclipse.equinox.common.tests/src/org/eclipse/equinox/common/tests/RuntimeTests.java
@@ -32,7 +32,8 @@ import org.junit.runners.Suite.SuiteClasses;
SubMonitorTest.class,
SubProgressTest.class,
URIUtilTest.class,
- URLTest.class
+ URLTest.class,
+ PlatformLogWriterTest.class
})
public class RuntimeTests {
// intentionally left blank
diff --git a/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/PlatformLogWriter.java b/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/PlatformLogWriter.java
index 952547cbd..5a8cf6ba5 100644
--- a/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/PlatformLogWriter.java
+++ b/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/PlatformLogWriter.java
@@ -135,17 +135,19 @@ public class PlatformLogWriter implements SynchronousLogListener, LogFilter {
private static IStatus convertRawEntryToStatus(LogEntry logEntry) {
int severity;
- switch (logEntry.getLevel()) {
- case LogService.LOG_ERROR :
+ switch (logEntry.getLogLevel()) {
+ case ERROR :
severity = IStatus.ERROR;
break;
- case LogService.LOG_WARNING :
+ case WARN :
severity = IStatus.WARNING;
break;
- case LogService.LOG_INFO :
+ case INFO :
severity = IStatus.INFO;
break;
- case LogService.LOG_DEBUG :
+ case DEBUG :
+ case TRACE :
+ case AUDIT :
severity = IStatus.OK;
break;
default :

Back to the top