Interface LoggerContext


@ProviderType public interface LoggerContext
Logger Context for a bundle.

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.

  • Field Details

    • LOGGER_CONTEXT_PID

      static final String LOGGER_CONTEXT_PID
      Logger Context PID.

      If Configuration Admin is present, Logger Context configuration information in Configuration Admin must be used. The name of the Logger Context is mapped to a Configuration Admin targeted PID as follows:

      • The root Logger Context, which has no name, is mapped to the PID org.osgi.service.log.admin.
      • A named Logger Context is mapped to a targeted PID by prefixing the Logger Context's name with org.osgi.service.log.admin followed by vertical line ('|' \u007c). For example, the Logger Context named com.foo.bar is mapped to the targeted PID org.osgi.service.log.admin|com.foo.bar.
      See Also:
    • LOGGER_CONTEXT_DEFAULT_LOGLEVEL

      static final String LOGGER_CONTEXT_DEFAULT_LOGLEVEL
      Framework launching property specifying the default log level of the root Logger Context.

      The value of this property must be the name of the one of the LogLevels.

      If not specified, or the specified value is not the name of the one of the LogLevels, the default log level of the root Logger Context is LogLevel.WARN.

      See Also:
  • Method Details

    • getName

      String getName()
      Returns the name for this Logger Context.
      Returns:
      The name for this Logger Context. The root Logger Context has no name and returns null.
    • getEffectiveLogLevel

      LogLevel getEffectiveLogLevel(String name)
      Returns the effective log level of the logger name in this Logger Context.

      The effective log level for a logger name is found by the following steps:

      1. If the specified logger name is configured with a log level, return the configured log level.
      2. For each ancestor logger name of the specified logger name, if the ancestor logger name is configured with a log level, return the configured log level.
      3. If this Logger Context is named, return the result of calling this method on the root Logger Context with the specified logger name.
      4. If this Logger Context is the root Logger Context, return the default log level of the root Logger Context.
      Parameters:
      name - The logger name.
      Returns:
      The effective log level of the logger name in this Logger Context.
    • getLogLevels

      Map<String,LogLevel> getLogLevels()
      Returns the configured log levels for this Logger Context.
      Returns:
      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 returned map is the property of the caller who can modify the map and use it as input to setLogLevels(Map). The returned map must support all optional Map operations.
    • setLogLevels

      void setLogLevels(Map<String,LogLevel> logLevels)
      Configure the log levels for this Logger Context.

      All previous log levels configured for this Logger Context are cleared and then the log levels in the specified map are configured.

      The configured log levels for this Logger Context can be set by both this method and by configuration information in Configuration Admin, if Configuration Admin is present. The configured log levels for this Logger Context are based upon the last technique used to update the configured log levels. This method must not modify or set configuration information in Configuration Admin.

      Parameters:
      logLevels - The log levels to configure for this Logger Context. The keys are the logger names and the values are the log levels. The specified map is the property of the caller and this method must not modify or retain the specified map.
    • clear

      void clear()
      Clear the configuration of this Logger Context.

      The configured log levels will be cleared.

    • isEmpty

      boolean isEmpty()
      Returns whether the configuration of this Logger Context is empty.
      Returns:
      true if this Logger Context has no configuration. That is, the configured log levels are empty. Otherwise false is returned.