diff options
author | Thomas Watson | 2016-03-04 14:30:44 +0000 |
---|---|---|
committer | Thomas Watson | 2017-06-16 12:38:08 +0000 |
commit | c7fae461022cd049802023f56bb518b8a81ad02a (patch) | |
tree | 87276855dc7fc1b82f10c56d1a24af4fd25df758 /bundles/org.eclipse.osgi/osgi/src | |
parent | f31b2c1056822bdc2e77b22f558a087943f7a22d (diff) | |
download | rt.equinox.framework-c7fae461022cd049802023f56bb518b8a81ad02a.tar.gz rt.equinox.framework-c7fae461022cd049802023f56bb518b8a81ad02a.tar.xz rt.equinox.framework-c7fae461022cd049802023f56bb518b8a81ad02a.zip |
Bug 486950 - [osgi R7] log service is being updated
- Add support for LoggerAdmin
Change-Id: Iecd2675cfb7ddf7f7a10fbaa8a7f35e4f59d5615
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
Diffstat (limited to 'bundles/org.eclipse.osgi/osgi/src')
11 files changed, 340 insertions, 26 deletions
diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/FormatterLogger.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/FormatterLogger.java index 964972b75..637d34fb8 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/FormatterLogger.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/FormatterLogger.java @@ -31,8 +31,8 @@ import org.osgi.annotation.versioning.ProviderType; * additional arguments. If the last argument is a {@code Throwable} or * {@code ServiceReference}, it is added to the generated {@link LogEntry} and * then if the next to last argument is a {@code ServiceReference} or - * {@code Throwable}, it is added to the generated {@link LogEntry}. For - * example: + * {@code Throwable} and not the same type as the last argument, it is added to + * the generated {@link LogEntry}. For example: * * <pre> * logger.info("Found service %s.", serviceReference, serviceReference); diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/LogEntry.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/LogEntry.java index 1b252eb63..6b3ee59f7 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/LogEntry.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/LogEntry.java @@ -54,12 +54,14 @@ public interface LogEntry { ServiceReference< ? > getServiceReference(); /** - * Returns the level of this {@code LogEntry} object. + * Returns the integer level of this {@code LogEntry} object. * <p> - * This is one of the severity levels defined by the {@code LogService} - * interface. + * If one of the {@code log} methods of {@link LogService} was used, this is + * the specified integer level. Otherwise, this is the + * {@link LogLevel#ordinal() ordinal} value of the {@link #getLogLevel() log + * level}. * - * @return Level of this {@code LogEntry} object. + * @return Integer level of this {@code LogEntry} object. * @deprecated Since 1.4. Replaced by {@link #getLogLevel()}. */ @Deprecated @@ -116,9 +118,7 @@ public interface LogEntry { * {@code LogEntry} object. * * @return The name of the {@link Logger} object used to create this - * {@code LogEntry} object or {@code ""} if this {@code LogEntry} - * object was created using one of the original {@code LogService} - * {@code log} methods. + * {@code LogEntry} object. * @since 1.4 */ String getLoggerName(); @@ -126,10 +126,9 @@ public interface LogEntry { /** * Returns the sequence number for this {@code LogEntry} object. * <p> - * The {@code LogService} assigns a unique, non-negative value that is - * larger than all previously assigned values since the {@code LogService} - * was started. These values are transient and are reused upon restart of - * the {@code LogService}. + * A unique, non-negative value that is larger than all previously assigned + * values since the log implementation was started. These values are + * transient and are reused upon restart of the log implementation. * * @return The sequence number for this {@code LogEntry} object. * @since 1.4 @@ -140,7 +139,8 @@ public interface LogEntry { * Returns a string representing the thread which created this * {@code LogEntry} object. * <p> - * This string contains the name of the thread. + * This string must contain the name of the thread and may contain other + * information about the thread. * * @return A string representing the thread which created this * {@code LogEntry} object. diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/LogLevel.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/LogLevel.java index 94053969d..ebc1f14a4 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/LogLevel.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/LogLevel.java @@ -61,6 +61,6 @@ public enum LogLevel { * {@code false} otherwise. */ public boolean implies(LogLevel other) { - return ordinal() <= other.ordinal(); + return ordinal() >= other.ordinal(); } } diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/LogListener.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/LogListener.java index 49bb6b7e4..4e6f645f4 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/LogListener.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/LogListener.java @@ -37,6 +37,7 @@ import org.osgi.annotation.versioning.ConsumerType; * @author $Id$ */ @ConsumerType +@FunctionalInterface public interface LogListener extends EventListener { /** * Listener method called for each LogEntry object created. diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/LogService.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/LogService.java index 983c2b524..55d10697b 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/LogService.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/LogService.java @@ -74,6 +74,19 @@ public interface LogService extends LoggerFactory { * <p> * The {@code ServiceReference} field and the {@code Throwable} field of the * {@code LogEntry} object will be set to {@code null}. + * <p> + * This method will log to the {@link Logger} named {@code "LogService"} for + * the bundle. The specified level is mapped to a {@link LogLevel} as + * follows: + * <ul> + * <li>{@link #LOG_ERROR} - {@link LogLevel#ERROR}</li> + * <li>{@link #LOG_WARNING} - {@link LogLevel#WARN}</li> + * <li>{@link #LOG_INFO} - {@link LogLevel#INFO}</li> + * <li>{@link #LOG_DEBUG} - {@link LogLevel#DEBUG}</li> + * <li>Any other value - {@link LogLevel#TRACE}</li> + * </ul> + * In the generated log entry, {@link LogEntry#getLevel()} must return the + * specified level. * * @param level The severity of the message. This should be one of the * defined log levels but may be any integer that is interpreted @@ -91,6 +104,19 @@ public interface LogService extends LoggerFactory { * <p> * The {@code ServiceReference} field of the {@code LogEntry} object will be * set to {@code null}. + * <p> + * This method will log to the {@link Logger} named {@code "LogService"} for + * the bundle. The specified level is mapped to a {@link LogLevel} as + * follows: + * <ul> + * <li>{@link #LOG_ERROR} - {@link LogLevel#ERROR}</li> + * <li>{@link #LOG_WARNING} - {@link LogLevel#WARN}</li> + * <li>{@link #LOG_INFO} - {@link LogLevel#INFO}</li> + * <li>{@link #LOG_DEBUG} - {@link LogLevel#DEBUG}</li> + * <li>Any other value - {@link LogLevel#TRACE}</li> + * </ul> + * In the generated log entry, {@link LogEntry#getLevel()} must return the + * specified level. * * @param level The severity of the message. This should be one of the * defined log levels but may be any integer that is interpreted @@ -111,6 +137,19 @@ public interface LogService extends LoggerFactory { * <p> * The {@code Throwable} field of the {@code LogEntry} will be set to * {@code null}. + * <p> + * This method will log to the {@link Logger} named {@code "LogService"} for + * the bundle. The specified level is mapped to a {@link LogLevel} as + * follows: + * <ul> + * <li>{@link #LOG_ERROR} - {@link LogLevel#ERROR}</li> + * <li>{@link #LOG_WARNING} - {@link LogLevel#WARN}</li> + * <li>{@link #LOG_INFO} - {@link LogLevel#INFO}</li> + * <li>{@link #LOG_DEBUG} - {@link LogLevel#DEBUG}</li> + * <li>Any other value - {@link LogLevel#TRACE}</li> + * </ul> + * In the generated log entry, {@link LogEntry#getLevel()} must return the + * specified level. * * @param sr The {@code ServiceReference} object of the service that this * message is associated with or {@code null}. @@ -128,6 +167,19 @@ public interface LogService extends LoggerFactory { /** * Logs a message with an exception associated and a * {@code ServiceReference} object. + * <p> + * This method will log to the {@link Logger} named {@code "LogService"} for + * the bundle. The specified level is mapped to a {@link LogLevel} as + * follows: + * <ul> + * <li>{@link #LOG_ERROR} - {@link LogLevel#ERROR}</li> + * <li>{@link #LOG_WARNING} - {@link LogLevel#WARN}</li> + * <li>{@link #LOG_INFO} - {@link LogLevel#INFO}</li> + * <li>{@link #LOG_DEBUG} - {@link LogLevel#DEBUG}</li> + * <li>Any other value - {@link LogLevel#TRACE}</li> + * </ul> + * In the generated log entry, {@link LogEntry#getLevel()} must return the + * specified level. * * @param sr The {@code ServiceReference} object of the service that this * message is associated with. diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/Logger.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/Logger.java index 564a0ad19..790a664f4 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/Logger.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/Logger.java @@ -34,8 +34,9 @@ import org.osgi.annotation.versioning.ProviderType; * additional arguments. If the last argument is a {@code Throwable} or * {@code ServiceReference}, it is added to the generated {@link LogEntry} and * then if the next to last argument is a {@code ServiceReference} or - * {@code Throwable}, it is added to the generated {@link LogEntry}. These - * arguments will not be used for place holders. For example: + * {@code Throwable} and not the same type as the last argument, it is added to + * the generated {@link LogEntry}. These arguments will not be used for place + * holders. For example: * * <pre> * logger.info("Found service {}.", serviceReference, serviceReference); @@ -50,6 +51,10 @@ import org.osgi.annotation.versioning.ProviderType; */ @ProviderType public interface Logger { + /** + * Root Logger Name. + */ + static String ROOT_LOGGER_NAME = "ROOT"; /** * Return the name of this Logger. 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 df1835468..3d17ce95f 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 @@ -23,6 +23,26 @@ import org.osgi.annotation.versioning.ProviderType; * <p> * Provides methods for bundles to obtain named {@link Logger}s that can be used * to write messages to the log. + * <p> + * Logger names should be in the form of a fully qualified Java class names with + * segments separated by full stop ({@code '.'} \u002E). For example: + * + * <pre> + * com.foo.Bar + * </pre> + * + * Logger names exist in a hierarchy. A logger name is said to be an ancestor of + * another logger name if the logger name followed by a full stop ({@code '.'} + * \u002E) is a prefix of the descendant logger name. The + * {@link Logger#ROOT_LOGGER_NAME root logger name} is the top ancestor of the + * logger name hierarchy. For example: + * + * <pre> + * com.foo.Bar + * com.foo + * com + * ROOT + * </pre> * * @ThreadSafe * @since 1.4 @@ -32,44 +52,50 @@ import org.osgi.annotation.versioning.ProviderType; public interface LoggerFactory { /** - * Return a {@link Logger} named with the specified name. + * Return the {@link Logger} named with the specified name. * * @param name The name to use for the logger name. - * @return A {@link Logger} named with the specified name. + * @return The {@link Logger} named with the specified name. If the name + * parameter is equal to {@link Logger#ROOT_LOGGER_NAME}, then the + * root logger is returned. */ Logger getLogger(String name); /** - * Return a {@link Logger} named with the specified class. + * Return the {@link Logger} named with the specified class. * * @param clazz The class to use for the logger name. - * @return A {@link Logger} named with the specified class. + * @return The {@link Logger} named with the name of the specified class. */ Logger getLogger(Class< ? > clazz); /** - * Return a {@link Logger} of the specified type named with the specified + * Return the {@link Logger} of the specified type named with the specified * name. * - * @param <L> A Logger type. + * @param <L> The Logger type. * @param name The name to use for the logger name. * @param loggerType The type of Logger. Can be {@link Logger} or * {@link FormatterLogger}. - * @return A {@link Logger} named with the specified name. + * @return The {@link Logger} or {@link FormatterLogger} named with the + * specified name. 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. */ <L extends Logger> L getLogger(String name, Class<L> loggerType); /** - * Return a {@link Logger} of the specified type named with the specified + * Return the {@link Logger} of the specified type named with the specified * class. * * @param <L> A Logger type. * @param clazz The class to use for the logger name. * @param loggerType The type of Logger. Can be {@link Logger} or * {@link FormatterLogger}. - * @return A {@link Logger} named with the specified class. + * @return The {@link Logger} or {@link FormatterLogger} named with the name + * of the specified class. * @throws IllegalArgumentException If the specified type is not a supported * Logger type. */ diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/admin/LoggerAdmin.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/admin/LoggerAdmin.java new file mode 100644 index 000000000..37c8ef2cf --- /dev/null +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/admin/LoggerAdmin.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) OSGi Alliance (2016). All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.osgi.service.log.admin; + +import org.osgi.annotation.versioning.ProviderType; +import org.osgi.service.log.LoggerFactory; + +/** + * LoggerAdmin service for configuring loggers. + * <p> + * Each bundle may have its own named {@link LoggerContext} based upon its + * bundle symbolic name, bundle version, and bundle location. There is also a + * root Logger Context from which each named Logger Context inherits. The root + * Logger Context has no name. + * <p> + * When a bundle logs, the logger implementation must locate the Logger Context + * for the bundle to determine the + * {@link LoggerContext#getEffectiveLogLevel(String) effective log level} of the + * logger name. The <i>best matching name</i> for the Logger Context is the + * longest name, which has a non-empty Logger Context, according to this syntax: + * + * <pre> + * name ::= symbolic-name ( ’|’ version ( ’|’ location )? )? + * </pre> + * + * The version must be formatted canonically, that is, according to the + * {@code toString()} method of the {@code Version} class. So the Logger Context + * for a bundle is searched for using the following names in the given order: + * + * <pre> + * <symbolic-name>|<version>|<location> + * <symbolic-name>|<version> + * <symbolic-name> + * </pre> + * + * If a non-empty Logger Context is not found, the Logger Context with the name + * {@code <symbolic-name>} is used for the bundle. + * + * @ThreadSafe + * @author $Id$ + */ +@ProviderType +public interface LoggerAdmin { + /** + * Logger Admin service property to associate the Logger Admin service with + * a {@link LoggerFactory} service. + * <p> + * This service property is set to the {@code service.id} for the + * {@link LoggerFactory} service administered by this Logger Admin. + * <p> + * The value of this service property must be of type {@code Long}. + */ + static String LOG_SERVICE_ID = "osgi.log.service.id"; + + /** + * Get the Logger Context for the specified name. + * + * @param name The name of the Logger Context. Can be {@code null} to + * specify the root Logger Context. + * @return The Logger Context for the specified name. + */ + LoggerContext getLoggerContext(String name); +} diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/admin/LoggerContext.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/admin/LoggerContext.java new file mode 100644 index 000000000..33b9e4b6f --- /dev/null +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/admin/LoggerContext.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) OSGi Alliance (2016). All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.osgi.service.log.admin; + +import java.util.Map; + +import org.osgi.annotation.versioning.ProviderType; +import org.osgi.service.log.LogLevel; + +/** + * Logger Context for a bundle. + * <p> + * Any change to the configuration of this Logger Context must be effective + * immediately for all loggers that would rely upon the configuration of this + * Logger Context. + * + * @ThreadSafe + * @author $Id$ + */ +@ProviderType +public interface LoggerContext { + /** + * Returns the name for this Logger Context. + * + * @return The name for this Logger Context. The root Logger Context has no + * name and returns {@code null}. + */ + String getName(); + + /** + * Returns the effective log level of the logger name in this Logger + * Context. + * <p> + * The effective log level for a logger name is found by the following + * steps: + * <ol> + * <li>If the specified logger name is configured with a non-null log level + * in this Logger Context, return the configured log level.</li> + * <li>For each ancestor logger name of the specified logger name, if the + * ancestor logger name is configured with a non-null log level in this + * Logger Context, return the configured log level.</li> + * <li>If the specified logger name is configured with a non-null log level + * in the root Logger Context, return the configured log level.</li> + * <li>For each ancestor logger name of the specified logger name, if the + * ancestor logger name is configured with a non-null log level in the root + * Logger Context, return the configured log level.</li> + * <li>Return {@link LogLevel#WARN} because no non-null log level has been + * found for the specified logger name or any of its ancestor logger names. + * </li> + * </ol> + * + * @param name The logger name. + * @return The effective log level of the logger name in this Logger + * Context. + */ + LogLevel getEffectiveLogLevel(String name); + + /** + * Returns the configured log levels for this Logger Context. + * + * @return The configured log levels for this Logger Context. The keys are + * the logger names and the values are the log levels. The returned + * map may be empty if no logger names are configured for this + * Logger Context. The log level value can be {@code null}. The + * returned map is the property of the caller who can modify the map + * and use it as input to {@link #setLogLevels(Map)}. The returned + * map must support all optional Map operations. + */ + Map<String,LogLevel> getLogLevels(); + + /** + * Configure the log levels for this Logger Context. + * <p> + * All previous log levels configured for this Logger Context are cleared + * and then the log levels in the specified map are configured. + * + * @param logLevels The log levels to configure for this Logger Context. The + * keys are the logger names and the values are the log levels. + * The log level value can be {@code null}. The specified map is + * the property of the caller and this method must not modify or + * retain the specified map. + */ + void setLogLevels(Map<String,LogLevel> logLevels); + + /** + * Clear the configuration of this Logger Context. + * <p> + * The configured log levels will be cleared. + */ + void clear(); + + /** + * Returns whether the configuration of this Logger Context is empty. + * + * @return {@code true} if this Logger Context has no configuration. That + * is, the configured log levels are empty. Otherwise {@code false} + * is returned. + */ + boolean isEmpty(); +} diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/admin/package-info.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/admin/package-info.java new file mode 100644 index 000000000..21f2c3493 --- /dev/null +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/admin/package-info.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) OSGi Alliance (2016). All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Log Admin Package Version 1.0. + * <p> + * Bundles wishing to use this package must list the package in the + * Import-Package header of the bundle's manifest. This package has two types of + * users: the consumers that use the API in this package and the providers that + * implement the API in this package. + * <p> + * Example import for consumers using the API in this package: + * <p> + * {@code Import-Package: org.osgi.service.log.admin; version="[1.0,2.0)"} + * <p> + * Example import for providers implementing the API in this package: + * <p> + * {@code Import-Package: org.osgi.service.log.admin; version="[1.0,1.1)"} + * + * @author $Id$ + */ +@Version("1.0") +package org.osgi.service.log.admin; + +import org.osgi.annotation.versioning.Version; diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/admin/packageinfo b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/admin/packageinfo new file mode 100644 index 000000000..7c8de0324 --- /dev/null +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/log/admin/packageinfo @@ -0,0 +1 @@ +version 1.0 |