From 9566e37ecdca4821070a7a45836264566c9f3c37 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Thu, 31 Mar 2016 11:32:19 -0500 Subject: Bug 486950 - [osgi R7] log service is being updated Implement new getLogger method that takes a bundle Change-Id: Ibd50163c2390c5853274cfa72662fd775c7f02ec Signed-off-by: Thomas Watson --- .../osgi/internal/log/ExtendedLogServiceImpl.java | 9 ++++++++ .../src/org/osgi/service/log/LoggerFactory.java | 26 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/ExtendedLogServiceImpl.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/ExtendedLogServiceImpl.java index a2dd568d6..cc4d186cd 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/ExtendedLogServiceImpl.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/ExtendedLogServiceImpl.java @@ -71,6 +71,15 @@ public class ExtendedLogServiceImpl implements ExtendedLogService { return bundleLogService.getLogger(name); } + @Override + public L getLogger(Bundle logBundle, String name, Class loggerType) { + if (logBundle == null || (logBundle.getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) != 0) { + throw new IllegalArgumentException("The bundle is not resolved: " + logBundle); //$NON-NLS-1$ + } + ExtendedLogService bundleLogService = factory.getLogService(logBundle); + return bundleLogService.getLogger(name, loggerType); + } + public String getName() { return getLogger((String) null).getName(); } diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/LoggerFactory.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/LoggerFactory.java index 3d17ce95f..61d256f03 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/LoggerFactory.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/LoggerFactory.java @@ -17,6 +17,7 @@ package org.osgi.service.log; import org.osgi.annotation.versioning.ProviderType; +import org.osgi.framework.Bundle; /** * Logger Factory service for logging information. @@ -100,4 +101,29 @@ public interface LoggerFactory { * Logger type. */ L getLogger(Class< ? > clazz, Class loggerType); + + /** + * Return the {@link Logger} of the specified type named with the specified + * name for the specified bundle. + *

+ * This method is not normally used. The other {@code getLogger} methods + * return a {@link Logger} associated with the bundle used to obtain this + * Logger Factory service. This method is used to obtain a {@link Logger} + * for the specified bundle which may be useful to code which is logging on + * behalf of another bundle. + * + * @param The Logger type. + * @param bundle The bundle associated with the Logger. + * @param name The name to use for the logger name. + * @param loggerType The type of Logger. Can be {@link Logger} or + * {@link FormatterLogger}. + * @return The {@link Logger} or {@link FormatterLogger} named with the + * specified name for the specified bundle. If the name parameter is + * equal to {@link Logger#ROOT_LOGGER_NAME}, then the root logger is + * returned. + * @throws IllegalArgumentException If the specified type is not a supported + * Logger type or the specified Bundle is not a resolved bundle. + */ + L getLogger(Bundle bundle, String name, + Class loggerType); } -- cgit v1.2.3