Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2016-03-11 17:17:25 -0500
committerThomas Watson2017-06-16 08:38:08 -0400
commit6ef43b45c7ae11c1859cf969d8e11f2dc53689cc (patch)
tree182dc23ebcf47e94bb3cb536cbc2686538d270b6 /bundles
parentc7fae461022cd049802023f56bb518b8a81ad02a (diff)
downloadrt.equinox.framework-6ef43b45c7ae11c1859cf969d8e11f2dc53689cc.tar.gz
rt.equinox.framework-6ef43b45c7ae11c1859cf969d8e11f2dc53689cc.tar.xz
rt.equinox.framework-6ef43b45c7ae11c1859cf969d8e11f2dc53689cc.zip
Bug 486950 - [osgi R7] log service is being updated
- fix bugs around formatting and LoggerAdmin Change-Id: I3c183c6996b9f05b206f972b5a63e6202de4c282 Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.osgi/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/Arguments.java19
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/ExtendedLogEntryImpl.java5
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/ExtendedLogReaderServiceFactory.java10
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/ExtendedLogServiceFactory.java4
-rwxr-xr-xbundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LoggerContextTargetMap.java2
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LoggerImpl.java45
7 files changed, 53 insertions, 34 deletions
diff --git a/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF
index 65ff2ba2e..cb69e00b5 100644
--- a/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF
@@ -67,7 +67,7 @@ Export-Package: org.eclipse.core.runtime.adaptor;x-friends:="org.eclipse.core.ru
org.osgi.resource;version="1.0",
org.osgi.resource.dto;version="1.0";uses:="org.osgi.dto",
org.osgi.service.condpermadmin;version="1.1.1";uses:="org.osgi.framework",
- org.osgi.service.log;version="1.3";uses:="org.osgi.framework",
+ org.osgi.service.log;version="1.4";uses:="org.osgi.framework",
org.osgi.service.log.admin;version="1.0",
org.osgi.service.packageadmin;version="1.2";uses:="org.osgi.framework",
org.osgi.service.permissionadmin;version="1.2",
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/Arguments.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/Arguments.java
index 9eeb9883b..6308feea1 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/Arguments.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/Arguments.java
@@ -25,19 +25,24 @@ public class Arguments {
ServiceReference<?> context = null;
Throwable exception = null;
Object object = arguments[arguments.length - 1];
- if (object instanceof Throwable) {
+ if (object instanceof Throwable || object instanceof ServiceReference) {
length--;
- exception = (Throwable) object;
+ if (object instanceof Throwable) {
+ exception = (Throwable) object;
+ } else {
+ context = (ServiceReference<?>) object;
+ }
if (arguments.length > 1) {
object = arguments[arguments.length - 2];
- if (object instanceof ServiceReference) {
+ if ((object instanceof ServiceReference && context == null) || (object instanceof Throwable && exception == null)) {
length--;
- context = (ServiceReference<?>) object;
+ if (object instanceof Throwable) {
+ exception = (Throwable) object;
+ } else {
+ context = (ServiceReference<?>) object;
+ }
}
}
- } else if (object instanceof ServiceReference) {
- length--;
- context = (ServiceReference<?>) object;
}
serviceReference = context;
throwable = 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 335acf19a..86eac4cc4 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
@@ -55,7 +55,7 @@ public class ExtendedLogEntryImpl implements ExtendedLogEntry, LogEntry {
return threadId.longValue();
}
- public ExtendedLogEntryImpl(Bundle bundle, String loggerName, 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, Throwable throwable) {
this.time = System.currentTimeMillis();
this.loggerName = loggerName;
this.bundle = bundle;
@@ -73,8 +73,7 @@ public class ExtendedLogEntryImpl implements ExtendedLogEntry, LogEntry {
this.sequenceNumber = nextSequenceNumber++;
}
- // TODO need to find the calling stack here not just 2 up.
- stackTraceElement = currentThread.getStackTrace()[2];
+ this.stackTraceElement = stackTraceElement;
}
public String getLoggerName() {
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 b6ef95760..1d00919a2 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
@@ -176,21 +176,21 @@ public class ExtendedLogReaderServiceFactory implements ServiceFactory<ExtendedL
return count;
}
- void log(final Bundle bundle, final String name, 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 Throwable exception) {
if (System.getSecurityManager() != null) {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
- logPrivileged(bundle, name, context, logLevelEnum, level, message, exception);
+ logPrivileged(bundle, name, stackTraceElement, context, logLevelEnum, level, message, exception);
return null;
}
});
} else {
- logPrivileged(bundle, name, context, logLevelEnum, level, message, exception);
+ logPrivileged(bundle, name, stackTraceElement, context, logLevelEnum, level, message, exception);
}
}
- void logPrivileged(Bundle bundle, String name, Object context, LogLevel logLevelEnum, int level, String message, Throwable exception) {
- LogEntry logEntry = new ExtendedLogEntryImpl(bundle, name, context, logLevelEnum, level, message, 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);
storeEntry(logEntry);
ArrayMap<LogListener, Object[]> listenersCopy;
listenersLock.readLock();
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 cf92c747e..11feeb46d 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
@@ -80,8 +80,8 @@ public class ExtendedLogServiceFactory implements ServiceFactory<ExtendedLogServ
return logReaderServiceFactory.isLoggable(bundle, name, level);
}
- void log(Bundle bundle, String name, Object context, LogLevel logLevelEnum, int level, String message, Throwable exception) {
- logReaderServiceFactory.log(bundle, name, context, logLevelEnum, level, message, exception);
+ 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 checkLogPermission() throws SecurityException {
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LoggerContextTargetMap.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LoggerContextTargetMap.java
index f22ff956a..ee098c0e5 100755
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LoggerContextTargetMap.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LoggerContextTargetMap.java
@@ -110,7 +110,7 @@ public class LoggerContextTargetMap {
EquinoxLoggerContext loggerContext = loggerContexts.get(name);
if (loggerContext == null) {
loggerContext = factory.createEquinoxLoggerContext(name);
- loggerContexts.put(null, loggerContext);
+ loggerContexts.put(name, loggerContext);
}
return loggerContext;
}
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 bf2f385b4..1876e10ba 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
@@ -17,7 +17,8 @@ import org.osgi.service.log.LogService;
import org.osgi.service.log.admin.LoggerContext;
public class LoggerImpl implements Logger {
-
+ static final String THIS_PACKAGE_NAME = LoggerImpl.class.getName().substring(0, LoggerImpl.class.getName().length() - LoggerImpl.class.getSimpleName().length());
+ static final Object[] EMPTY = new Object[0];
protected final ExtendedLogServiceImpl logServiceImpl;
protected final String name;
@@ -72,7 +73,7 @@ public class LoggerImpl implements Logger {
logLevelEnum = getLogLevel(level);
}
if (enabledLevel.implies(logLevelEnum)) {
- logServiceImpl.getFactory().log(entryBundle, name, context, logLevelEnum, level, message, exception);
+ logServiceImpl.getFactory().log(entryBundle, name, getLocation(), context, logLevelEnum, level, message, exception);
}
}
@@ -99,12 +100,12 @@ public class LoggerImpl implements Logger {
@Override
public void trace(String message) {
- trace(message, (Object) null);
+ trace(message, EMPTY);
}
@Override
public void trace(String format, Object arg) {
- trace(format, arg, null);
+ trace(format, new Object[] {arg});
}
@Override
@@ -124,12 +125,12 @@ public class LoggerImpl implements Logger {
@Override
public void debug(String message) {
- debug(message, (Object) null);
+ debug(message, EMPTY);
}
@Override
public void debug(String format, Object arg) {
- debug(format, arg, null);
+ debug(format, new Object[] {arg});
}
@Override
@@ -149,12 +150,12 @@ public class LoggerImpl implements Logger {
@Override
public void info(String message) {
- info(message, (Object) null);
+ info(message, EMPTY);
}
@Override
public void info(String format, Object arg) {
- info(format, arg, null);
+ info(format, new Object[] {arg});
}
@Override
@@ -174,12 +175,12 @@ public class LoggerImpl implements Logger {
@Override
public void warn(String message) {
- warn(message, (Object) null);
+ warn(message, EMPTY);
}
@Override
public void warn(String format, Object arg) {
- warn(format, arg, null);
+ warn(format, new Object[] {arg});
}
@Override
@@ -199,12 +200,12 @@ public class LoggerImpl implements Logger {
@Override
public void error(String message) {
- error(message, (Object) null);
+ error(message, EMPTY);
}
@Override
public void error(String format, Object arg) {
- error(format, arg, null);
+ error(format, new Object[] {arg});
}
@Override
@@ -219,12 +220,12 @@ public class LoggerImpl implements Logger {
@Override
public void audit(String message) {
- audit(message, (Object) null);
+ audit(message, EMPTY);
}
@Override
public void audit(String format, Object arg) {
- audit(format, arg, null);
+ audit(format, new Object[] {arg});
}
@Override
@@ -243,9 +244,23 @@ public class LoggerImpl implements Logger {
if (!enabledLevel.implies(level)) {
return;
}
+ StackTraceElement location = getLocation();
Arguments processedArguments = new Arguments(arguments);
String message = processedArguments.isEmpty() ? format : formatMessage(format, processedArguments);
- logServiceImpl.getFactory().log(logServiceImpl.getBundle(), name, processedArguments.serviceReference(), level, level.ordinal(), message.toString(), processedArguments.throwable());
+ logServiceImpl.getFactory().log(logServiceImpl.getBundle(), name, location, processedArguments.serviceReference(), level, level.ordinal(), message.toString(), processedArguments.throwable());
+ }
+
+ private StackTraceElement getLocation() {
+ StackTraceElement[] elements = Thread.currentThread().getStackTrace();
+ if (elements.length == 0) {
+ return null;
+ }
+ for (int i = 1; i < elements.length; i++) {
+ if (!elements[i].getClassName().startsWith(THIS_PACKAGE_NAME)) {
+ return elements[i];
+ }
+ }
+ return elements[1];
}
String formatMessage(String format, Arguments processedArguments) {

Back to the top