/** * Creates a {@link LoggerFactory logger factory} instance of the given preferred type. * <p> * The type of the created logger factory doesn't necessarily match the given preferred type. For example, if * {@code hazelcast.logging.class} system property is set, the configured logger factory class will be used * despite the given preferred type. Also, if factory instance construction is failed for some reason, * {@link StandardLoggerFactory} instance will be returned instead. * * @param preferredType the preferred type of the logger factory to create. * @return the created logger factory. */ public static LoggerFactory newLoggerFactory(String preferredType) { // creation of a new logger factory is not a performance critical operation, so we can afford doing it under the lock // and perform many non-cached accesses to volatile loggerFactory field to simplify the code synchronized (FACTORY_LOCK) { LoggerFactory obtainedFactory; obtainedFactory = tryToObtainFactoryByConfiguredClass(); if (obtainedFactory != null) { return obtainedFactory; } obtainedFactory = tryToObtainFactoryByPreferredType(preferredType); if (obtainedFactory != null) { return obtainedFactory; } assert StringUtil.isNullOrEmpty(preferredType); obtainedFactory = obtainFactoryByRecoveringFromNullOrEmptyPreferredType(); return obtainedFactory; } }
/** * Creates a {@link LoggerFactory logger factory} instance of the given preferred type. * <p> * The type of the created logger factory doesn't necessarily match the given preferred type. For example, if * {@code hazelcast.logging.class} system property is set, the configured logger factory class will be used * despite the given preferred type. Also, if factory instance construction is failed for some reason, * {@link StandardLoggerFactory} instance will be returned instead. * * @param preferredType the preferred type of the logger factory to create. * @return the created logger factory. */ public static LoggerFactory newLoggerFactory(String preferredType) { // creation of a new logger factory is not a performance critical operation, so we can afford doing it under the lock // and perform many non-cached accesses to volatile loggerFactory field to simplify the code synchronized (FACTORY_LOCK) { LoggerFactory obtainedFactory; obtainedFactory = tryToObtainFactoryByConfiguredClass(); if (obtainedFactory != null) { return obtainedFactory; } obtainedFactory = tryToObtainFactoryByPreferredType(preferredType); if (obtainedFactory != null) { return obtainedFactory; } assert StringUtil.isNullOrEmpty(preferredType); obtainedFactory = obtainFactoryByRecoveringFromNullOrEmptyPreferredType(); return obtainedFactory; } }