Class LoggerFactory

java.lang.Object
org.eclipse.keyple.core.util.logging.LoggerFactory

public final class LoggerFactory extends Object
A factory class for creating and managing Logger instances.

This class provides a centralized mechanism to retrieve loggers for specific classes and allows dynamic configuration of the underlying LoggerProvider implementation. By default, it initializes a LoggerProvider using the ServiceLoader mechanism, but it also provides a method to programmatically set a custom provider.

The default implementation uses temporary a Slf4jLoggerProvider if no suitable LoggerProvider is found, ensuring that logging operations perform no actions.

This class is thread-safe and ensures only one LoggerProvider is active at any given time.

Since:
2.5.0
  • Method Details

    • setProvider

      public static void setProvider(LoggerProvider provider)
      Sets the LoggerProvider to be used by the LoggerFactory.

      This method allows overriding the default logger provider with a custom implementation. It is typically used to integrate a specific logging framework or behavior.

      Android / ProGuard troubleshooting: on Android, if code shrinking removes the provider implementation, the provider must be set explicitly.

      Parameters:
      provider - the LoggerProvider instance to set; must not be null
      Since:
      2.5.0
    • getLogger

      public static Logger getLogger(Class<?> clazz)
      Retrieves a Logger instance associated with the specified class. The logger can be used for logging messages at various levels, enabling class-specific logging behavior.
      Parameters:
      clazz - the class for which the logger is to be retrieved; must not be null
      Returns:
      the Logger instance associated with the specified class
      Since:
      2.5.0