Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2018-06-15 19:22:41 +0000
committerThomas Watson2018-06-15 19:22:41 +0000
commit1ef3b47bd321f7178023e0998045c261e72cc837 (patch)
treefb3d3f94557b0c5902acf57ad82c07110626104e
parent5b50d3ba90ecf2540edaa0d42f2f6e5b109005ba (diff)
downloadrt.equinox.framework-1ef3b47bd321f7178023e0998045c261e72cc837.tar.gz
rt.equinox.framework-1ef3b47bd321f7178023e0998045c261e72cc837.tar.xz
rt.equinox.framework-1ef3b47bd321f7178023e0998045c261e72cc837.zip
Bug 535963 - [log] ExtendedLogEntry.getContext should use event asI20180618-0800
context Change-Id: Iefb2734f9f04a90811fda9bfb38446f5bd486380 Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogReaderServiceTest.java47
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/ExtendedLogEntryImpl.java11
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/ExtendedLogReaderServiceFactory.java13
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/ExtendedLogServiceFactory.java17
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LogServiceManager.java10
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LoggerImpl.java22
6 files changed, 78 insertions, 42 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogReaderServiceTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogReaderServiceTest.java
index 2cf330135..f68ee39be 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogReaderServiceTest.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogReaderServiceTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2014 IBM Corporation and others All rights reserved. This
+ * Copyright (c) 2007, 2018 IBM Corporation 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
@@ -18,6 +18,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
+import org.eclipse.equinox.log.ExtendedLogEntry;
import org.eclipse.equinox.log.SynchronousLogListener;
import org.eclipse.osgi.container.Module;
import org.eclipse.osgi.container.ModuleContainerAdaptor.ContainerEvent;
@@ -26,8 +27,11 @@ import org.eclipse.osgi.launch.Equinox;
import org.eclipse.osgi.tests.OSGiTestsActivator;
import org.eclipse.osgi.tests.bundles.AbstractBundleTests;
import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.log.LogEntry;
@@ -151,7 +155,11 @@ public class LogReaderServiceTest extends AbstractBundleTests {
testBundle.start();
listener.waitForLogEntry();
}
- assertTrue(listener.getEntryX().getLevel() == LogService.LOG_INFO);
+
+ ExtendedLogEntry entry = listener.getEntryX();
+ assertTrue(entry.getLevel() == LogService.LOG_INFO);
+ assertEquals("Wrong level.", LogLevel.INFO, entry.getLogLevel());
+ assertTrue("Wrong context: " + entry.getContext(), entry.getContext() instanceof BundleEvent);
}
public void testLogBundleEventSynchronous() throws Exception {
@@ -179,7 +187,10 @@ public class LogReaderServiceTest extends AbstractBundleTests {
OSGiTestsActivator.getContext().registerService(Object.class.getName(), new Object(), null);
listener.waitForLogEntry();
}
- assertTrue(listener.getEntryX().getLevel() == LogService.LOG_INFO);
+ ExtendedLogEntry entry = listener.getEntryX();
+ assertTrue(entry.getLevel() == LogService.LOG_INFO);
+ assertEquals("Wrong level.", LogLevel.INFO, entry.getLogLevel());
+ assertTrue("Wrong context: " + entry.getContext(), entry.getContext() instanceof ServiceEvent);
}
public void testLogServiceEventDebug() throws Exception {
@@ -191,18 +202,34 @@ public class LogReaderServiceTest extends AbstractBundleTests {
registration.setProperties(new Hashtable());
listener.waitForLogEntry();
}
- assertTrue(listener.getEntryX().getLevel() == LogService.LOG_DEBUG);
+ ExtendedLogEntry entry = listener.getEntryX();
+ assertTrue(entry.getLevel() == LogService.LOG_DEBUG);
+ assertEquals("Wrong level.", LogLevel.DEBUG, entry.getLogLevel());
+ assertTrue("Wrong context: " + entry.getContext(), entry.getContext() instanceof ServiceEvent);
}
public void testLogFrameworkEvent() throws Exception {
Bundle testBundle = installer.installBundle("test.logging.a"); //$NON-NLS-1$
- TestListener listener = new TestListener(testBundle);
+ final AtomicReference<LogEntry> logEntry = new AtomicReference<>();
+ final CountDownLatch countDown = new CountDownLatch(1);
+ LogListener listener = new LogListener() {
+ @Override
+ public void logged(LogEntry entry) {
+ if ("Events.Framework".equals(entry.getLoggerName())) {
+ logEntry.set(entry);
+ countDown.countDown();
+ }
+ }
+ };
reader.addLogListener(listener);
- synchronized (listener) {
- installer.refreshPackages(new Bundle[] {testBundle});
- listener.waitForLogEntry();
- }
- assertTrue(listener.getEntryX().getLevel() == LogService.LOG_INFO);
+ installer.refreshPackages(new Bundle[] {testBundle});
+
+ countDown.await(5, TimeUnit.SECONDS);
+
+ ExtendedLogEntry entry = (ExtendedLogEntry) logEntry.get();
+ assertTrue(entry.getLevel() == LogService.LOG_INFO);
+ assertEquals("Wrong level.", LogLevel.INFO, entry.getLogLevel());
+ assertTrue("Wrong context: " + entry.getContext(), entry.getContext() instanceof FrameworkEvent);
}
public void testLogFrameworkEventType() throws Exception {
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/ExtendedLogEntryImpl.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/ExtendedLogEntryImpl.java
index 86eac4cc4..b686c5871 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/ExtendedLogEntryImpl.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/ExtendedLogEntryImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2016 Cognos Incorporated, IBM Corporation and others
+ * Copyright (c) 2006, 2018 Cognos Incorporated, IBM Corporation 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
@@ -26,6 +26,7 @@ public class ExtendedLogEntryImpl implements ExtendedLogEntry, LogEntry {
private final int level;
private final LogLevel logLevelEnum;
private final String message;
+ private final ServiceReference<?> ref;
private final Throwable throwable;
private final Object contextObject;
private final long time;
@@ -55,7 +56,7 @@ public class ExtendedLogEntryImpl implements ExtendedLogEntry, LogEntry {
return threadId.longValue();
}
- public ExtendedLogEntryImpl(Bundle bundle, String loggerName, StackTraceElement stackTraceElement, Object contextObject, LogLevel logLevelEnum, int level, String message, Throwable throwable) {
+ public ExtendedLogEntryImpl(Bundle bundle, String loggerName, StackTraceElement stackTraceElement, Object contextObject, LogLevel logLevelEnum, int level, String message, ServiceReference<?> ref, Throwable throwable) {
this.time = System.currentTimeMillis();
this.loggerName = loggerName;
this.bundle = bundle;
@@ -63,6 +64,7 @@ public class ExtendedLogEntryImpl implements ExtendedLogEntry, LogEntry {
this.logLevelEnum = logLevelEnum;
this.message = message;
this.throwable = throwable;
+ this.ref = ref;
this.contextObject = contextObject;
Thread currentThread = Thread.currentThread();
@@ -110,10 +112,7 @@ public class ExtendedLogEntryImpl implements ExtendedLogEntry, LogEntry {
}
public ServiceReference<?> getServiceReference() {
- if (contextObject != null && contextObject instanceof ServiceReference)
- return (ServiceReference<?>) contextObject;
-
- return null;
+ return ref;
}
public long getTime() {
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/ExtendedLogReaderServiceFactory.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/ExtendedLogReaderServiceFactory.java
index 823ac2453..a54dd3d80 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/ExtendedLogReaderServiceFactory.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/ExtendedLogReaderServiceFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2017 Cognos Incorporated, IBM Corporation and others
+ * Copyright (c) 2006, 2018 Cognos Incorporated, IBM Corporation 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
@@ -29,6 +29,7 @@ import org.eclipse.osgi.internal.framework.EquinoxContainer;
import org.eclipse.osgi.internal.log.OrderedExecutor.OrderedTaskQueue;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.log.LogEntry;
import org.osgi.service.log.LogLevel;
@@ -209,21 +210,21 @@ public class ExtendedLogReaderServiceFactory implements ServiceFactory<ExtendedL
return count;
}
- void log(final Bundle bundle, final String name, final StackTraceElement stackTraceElement, final Object context, final LogLevel logLevelEnum, final int level, final String message, final Throwable exception) {
+ void log(final Bundle bundle, final String name, final StackTraceElement stackTraceElement, final Object context, final LogLevel logLevelEnum, final int level, final String message, final ServiceReference<?> ref, final Throwable exception) {
if (System.getSecurityManager() != null) {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
- logPrivileged(bundle, name, stackTraceElement, context, logLevelEnum, level, message, exception);
+ logPrivileged(bundle, name, stackTraceElement, context, logLevelEnum, level, message, ref, exception);
return null;
}
});
} else {
- logPrivileged(bundle, name, stackTraceElement, context, logLevelEnum, level, message, exception);
+ logPrivileged(bundle, name, stackTraceElement, context, logLevelEnum, level, message, ref, exception);
}
}
- void logPrivileged(Bundle bundle, String name, StackTraceElement stackTraceElement, Object context, LogLevel logLevelEnum, int level, String message, Throwable exception) {
- LogEntry logEntry = new ExtendedLogEntryImpl(bundle, name, stackTraceElement, context, logLevelEnum, level, message, exception);
+ void logPrivileged(Bundle bundle, String name, StackTraceElement stackTraceElement, Object context, LogLevel logLevelEnum, int level, String message, ServiceReference<?> ref, Throwable exception) {
+ LogEntry logEntry = new ExtendedLogEntryImpl(bundle, name, stackTraceElement, context, logLevelEnum, level, message, ref, exception);
storeEntry(logEntry);
ArrayMap<LogListener, Object[]> listenersCopy;
listenersLock.readLock().lock();
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/ExtendedLogServiceFactory.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/ExtendedLogServiceFactory.java
index e20994355..fa490933f 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/ExtendedLogServiceFactory.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/ExtendedLogServiceFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2017 Cognos Incorporated, IBM Corporation and others
+ * Copyright (c) 2006, 2018 Cognos Incorporated, IBM Corporation 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
@@ -9,12 +9,19 @@ package org.eclipse.osgi.internal.log;
import java.security.AccessController;
import java.security.Permission;
-import java.util.*;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.eclipse.equinox.log.ExtendedLogService;
import org.eclipse.equinox.log.LogPermission;
import org.eclipse.osgi.framework.util.SecureAction;
-import org.osgi.framework.*;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
import org.osgi.service.log.LogLevel;
import org.osgi.service.log.Logger;
import org.osgi.service.log.admin.LoggerAdmin;
@@ -80,8 +87,8 @@ public class ExtendedLogServiceFactory implements ServiceFactory<ExtendedLogServ
return logReaderServiceFactory.isLoggable(bundle, name, level);
}
- void log(Bundle bundle, String name, StackTraceElement stackTraceElement, Object context, LogLevel logLevelEnum, int level, String message, Throwable exception) {
- logReaderServiceFactory.log(bundle, name, stackTraceElement, context, logLevelEnum, level, message, exception);
+ void log(Bundle bundle, String name, StackTraceElement stackTraceElement, Object context, LogLevel logLevelEnum, int level, String message, ServiceReference<?> ref, Throwable exception) {
+ logReaderServiceFactory.log(bundle, name, stackTraceElement, context, logLevelEnum, level, message, ref, exception);
}
void checkLogPermission() throws SecurityException {
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LogServiceManager.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LogServiceManager.java
index 96fc535fe..c08d9f7ae 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LogServiceManager.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LogServiceManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2017 Cognos Incorporated, IBM Corporation and others
+ * Copyright (c) 2006, 2018 Cognos Incorporated, IBM Corporation 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
@@ -127,7 +127,7 @@ public class LogServiceManager implements SynchronousBundleListener, FrameworkLi
Bundle bundle = event.getBundle();
if (logReaderServiceFactory.isLoggable(bundle, LOGGER_BUNDLE_EVENT, LogService.LOG_INFO)) {
LoggerImpl logger = (LoggerImpl) systemBundleLog.getLogger(LOGGER_BUNDLE_EVENT);
- logger.log(bundle, null, null, LogService.LOG_INFO, getBundleEventTypeName(event.getType()), null);
+ logger.log(bundle, event, null, LogService.LOG_INFO, getBundleEventTypeName(event.getType()), null, null);
}
}
@@ -143,7 +143,7 @@ public class LogServiceManager implements SynchronousBundleListener, FrameworkLi
int logType = (eventType == ServiceEvent.MODIFIED) ? LogService.LOG_DEBUG : LogService.LOG_INFO;
if (logReaderServiceFactory.isLoggable(bundle, LOGGER_SERVICE_EVENT, logType)) {
LoggerImpl logger = (LoggerImpl) systemBundleLog.getLogger(LOGGER_SERVICE_EVENT);
- logger.log(bundle, reference, null, logType, getServiceEventTypeName(eventType), null);
+ logger.log(bundle, event, null, logType, getServiceEventTypeName(eventType), reference, null);
}
}
@@ -151,10 +151,10 @@ public class LogServiceManager implements SynchronousBundleListener, FrameworkLi
* FrameworkListener.frameworkEvent method.
*
*/
+ @SuppressWarnings("deprecation")
public void frameworkEvent(FrameworkEvent event) {
Bundle bundle = event.getBundle();
int eventType = event.getType();
- @SuppressWarnings("deprecation")
int logType;
switch (eventType) {
case FrameworkEvent.ERROR :
@@ -170,7 +170,7 @@ public class LogServiceManager implements SynchronousBundleListener, FrameworkLi
if (logReaderServiceFactory.isLoggable(bundle, LOGGER_FRAMEWORK_EVENT, logType)) {
LoggerImpl logger = (LoggerImpl) systemBundleLog.getLogger(LOGGER_FRAMEWORK_EVENT);
- logger.log(bundle, null, null, logType, getFrameworkEventTypeName(eventType), event.getThrowable());
+ logger.log(bundle, event, null, logType, getFrameworkEventTypeName(eventType), null, event.getThrowable());
}
}
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LoggerImpl.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LoggerImpl.java
index 90a2ee3bf..ec1678d18 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LoggerImpl.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LoggerImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2012 Cognos Incorporated, IBM Corporation and others
+ * Copyright (c) 2006, 2018 Cognos Incorporated, IBM Corporation 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
@@ -12,7 +12,9 @@ import java.util.regex.Pattern;
import org.eclipse.equinox.log.Logger;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceReference;
-import org.osgi.service.log.*;
+import org.osgi.service.log.LogLevel;
+import org.osgi.service.log.LogService;
+import org.osgi.service.log.LoggerConsumer;
import org.osgi.service.log.admin.LoggerContext;
public class LoggerImpl implements Logger {
@@ -47,12 +49,12 @@ public class LoggerImpl implements Logger {
@SuppressWarnings("rawtypes")
public void log(ServiceReference sr, int level, String message) {
- log(sr, level, message, null);
+ log(sr, null, level, message, sr, null);
}
@SuppressWarnings("rawtypes")
public void log(ServiceReference sr, int level, String message, Throwable exception) {
- log(sr, null, level, message, exception);
+ log(sr, null, level, message, sr, exception);
}
public void log(Object context, int level, String message) {
@@ -60,19 +62,19 @@ public class LoggerImpl implements Logger {
}
public void log(Object context, int level, String message, Throwable exception) {
- log(context, null, level, message, exception);
+ log(context, null, level, message, null, exception);
}
- private void log(Object context, LogLevel logLevelEnum, int level, String message, Throwable exception) {
- log(logServiceImpl.getBundle(), context, logLevelEnum, level, message, exception);
+ private void log(Object context, LogLevel logLevelEnum, int level, String message, ServiceReference<?> ref, Throwable exception) {
+ log(logServiceImpl.getBundle(), context, logLevelEnum, level, message, ref, exception);
}
- void log(Bundle entryBundle, Object context, LogLevel logLevelEnum, int level, String message, Throwable exception) {
+ void log(Bundle entryBundle, Object context, LogLevel logLevelEnum, int level, String message, ServiceReference<?> ref, Throwable exception) {
if (logLevelEnum == null) {
logLevelEnum = getLogLevel(level);
}
if (enabledLevel.implies(logLevelEnum)) {
- logServiceImpl.getFactory().log(entryBundle, name, getLocation(), context, logLevelEnum, level, message, exception);
+ logServiceImpl.getFactory().log(entryBundle, name, getLocation(), context, logLevelEnum, level, message, ref, exception);
}
}
@@ -281,7 +283,7 @@ public class LoggerImpl implements Logger {
StackTraceElement location = getLocation();
Arguments processedArguments = new Arguments(arguments);
String message = processedArguments.isEmpty() ? format : formatMessage(format, processedArguments);
- logServiceImpl.getFactory().log(logServiceImpl.getBundle(), name, location, processedArguments.serviceReference(), level, level.ordinal(), message.toString(), processedArguments.throwable());
+ logServiceImpl.getFactory().log(logServiceImpl.getBundle(), name, location, processedArguments.serviceReference(), level, level.ordinal(), message.toString(), processedArguments.serviceReference(), processedArguments.throwable());
}
private StackTraceElement getLocation() {

Back to the top