Class LoggerFactory
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 Summary
Modifier and TypeMethodDescriptionstatic LoggerRetrieves aLoggerinstance associated with the specified class.static voidsetProvider(LoggerProvider provider) Sets theLoggerProviderto be used by theLoggerFactory.
-
Method Details
-
setProvider
Sets theLoggerProviderto be used by theLoggerFactory.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- theLoggerProviderinstance to set; must not be null- Since:
- 2.5.0
-
getLogger
Retrieves aLoggerinstance 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
Loggerinstance associated with the specified class - Since:
- 2.5.0
-