Interface LoggerFactory

All Known Subinterfaces:
LogService

@ProviderType public interface LoggerFactory
Logger Factory service for logging information.

Provides methods for bundles to obtain named Loggers that can be used to write messages to the log.

Logger names should be in the form of a fully qualified Java class names with segments separated by full stop ('.' \u002E). For example:

 com.foo.Bar
 
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 ('.' \u002E) is a prefix of the descendant logger name. The root logger name is the top ancestor of the logger name hierarchy. For example:
 com.foo.Bar
 com.foo
 com
 ROOT
 
Since:
1.4
  • Method Details

    • getLogger

      default Logger getLogger(String name)
      Return the Logger named with the specified name.
      Parameters:
      name - The name to use for the logger name. Must not be null.
      Returns:
      The Logger named with the specified name. If the name parameter is equal to Logger.ROOT_LOGGER_NAME, then the root logger is returned.
    • getLogger

      default Logger getLogger(Class<?> clazz)
      Return the Logger named with the specified class.
      Parameters:
      clazz - The class to use for the logger name. Must not be null.
      Returns:
      The Logger named with the name of the specified class.
    • getLogger

      default <L extends Logger> L getLogger(String name, Class<L> loggerType)
      Return the Logger of the specified type named with the specified name.
      Type Parameters:
      L - The Logger type.
      Parameters:
      name - The name to use for the logger name. Must not be null.
      loggerType - The type of Logger. Can be Logger or FormatterLogger.
      Returns:
      The Logger or FormatterLogger named with the specified name. If the name parameter is equal to Logger.ROOT_LOGGER_NAME, then the root logger is returned.
      Throws:
      IllegalArgumentException - If the specified type is not a supported Logger type.
    • getLogger

      default <L extends Logger> L getLogger(Class<?> clazz, Class<L> loggerType)
      Return the Logger of the specified type named with the specified class.
      Type Parameters:
      L - A Logger type.
      Parameters:
      clazz - The class to use for the logger name. Must not be null.
      loggerType - The type of Logger. Can be Logger or FormatterLogger. Must not be null.
      Returns:
      The Logger or FormatterLogger named with the name of the specified class.
      Throws:
      IllegalArgumentException - If the specified type is not a supported Logger type.
    • getLogger

      default <L extends Logger> L getLogger(Bundle bundle, String name, Class<L> loggerType)
      Return the Logger of the specified type named with the specified name for the specified bundle.

      This method is not normally used. The other getLogger methods return a Logger associated with the bundle used to obtain this Logger Factory service. This method is used to obtain a Logger for the specified bundle which may be useful to code which is logging on behalf of another bundle.

      Type Parameters:
      L - The Logger type.
      Parameters:
      bundle - The bundle associated with the Logger. Must not be null.
      name - The name to use for the logger name. Must not be null.
      loggerType - The type of Logger. Can be Logger or FormatterLogger. Must not be null.
      Returns:
      The Logger or FormatterLogger named with the specified name for the specified bundle. If the name parameter is equal to 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.