Class MockLoggerFactory
java.lang.Object
io.micrometer.core.util.internal.logging.InternalLoggerFactory
io.micrometer.core.util.internal.logging.MockLoggerFactory
public class MockLoggerFactory
extends io.micrometer.core.util.internal.logging.InternalLoggerFactory
Simple
InternalLoggerFactory implementation that always returns an instance of
MockLogger so components that fetch the logger this way:
InternalLogger logger = InternalLoggerFactory.getInstance(MyClass.class);,
get a MockLogger instance if they are created using
factory.injectLogger(MyClass::new) or if
InternalLoggerFactory.setDefaultFactory(mockLoggerFactory); was set
previously.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionA convenient way to create a logger.A convenient way to create a logger.<T> TinjectLogger(Supplier<T> supplier) A factory method that returns the result of the givenSupplierand also injects the default factory.protected io.micrometer.core.util.internal.logging.InternalLoggernewInstance(String name) Methods inherited from class io.micrometer.core.util.internal.logging.InternalLoggerFactory
getDefaultFactory, getInstance, getInstance, setDefaultFactory
-
Constructor Details
-
MockLoggerFactory
public MockLoggerFactory()
-
-
Method Details
-
getLogger
A convenient way to create a logger. In contrast ofInternalLoggerFactory.getInstance(Class), this method returns aMockLoggerinstead of anInternalLoggerFactoryso that you don't need to cast.- Parameters:
clazz- The class that you need the logger for.- Returns:
- An instance of
MockLoggerfor the provided class.
-
getLogger
A convenient way to create a logger. In contrast ofInternalLoggerFactory.getInstance(String), this method returns aMockLoggerinstead of anInternalLoggerFactoryso that you don't need to cast.- Parameters:
name- The name of the logger.- Returns:
- An instance of
MockLoggerfor the provided name.
-
injectLogger
A factory method that returns the result of the givenSupplierand also injects the default factory. So if the logger is created this way:InternalLogger logger = InternalLoggerFactory.getInstance(MyClass.class);, the resulted logger will be aMockLogger.NOTE: This doesn't work when a target logger is a static field and has been initialized already. Use a non-static field for a target logger to make this work consistently.
- Type Parameters:
T- The type of an object that will be created by theSupplier.- Parameters:
supplier- The logic that creates the object you need to inject the logger into.- Returns:
- The result of the
Supplier.
-
newInstance
- Specified by:
newInstancein classio.micrometer.core.util.internal.logging.InternalLoggerFactory
-