This is an automated email from the ASF dual-hosted git repository.

mattsicker pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/master by this push:
     new 3b24330da0 Add MessageFactory and FlowMessageFactory to LoggingSystem
3b24330da0 is described below

commit 3b24330da0209f7510ad487d711642e12be49cf5
Author: Matt Sicker <[email protected]>
AuthorDate: Sat Nov 12 18:45:09 2022 -0600

    Add MessageFactory and FlowMessageFactory to LoggingSystem
    
    Signed-off-by: Matt Sicker <[email protected]>
---
 .../apache/logging/log4j/spi/AbstractLogger.java   | 73 +++--------------
 .../apache/logging/log4j/spi/LoggerRegistry.java   | 13 ++--
 .../apache/logging/log4j/spi/LoggingSystem.java    | 91 +++++++++++++++-------
 .../org/apache/logging/log4j/core/LoggerTest.java  | 23 +++---
 .../logging/log4j/taglib/SetLoggerTagTest.java     |  4 +-
 .../java/org/apache/logging/slf4j/LoggerTest.java  | 41 +++++-----
 6 files changed, 112 insertions(+), 133 deletions(-)

diff --git 
a/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java 
b/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
index c5b3114711..5cd2ada3a5 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
@@ -27,23 +27,19 @@ import org.apache.logging.log4j.LoggingException;
 import org.apache.logging.log4j.Marker;
 import org.apache.logging.log4j.MarkerManager;
 import org.apache.logging.log4j.internal.DefaultLogBuilder;
-import org.apache.logging.log4j.message.DefaultFlowMessageFactory;
 import org.apache.logging.log4j.message.EntryMessage;
 import org.apache.logging.log4j.message.FlowMessageFactory;
 import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.MessageFactory;
 import org.apache.logging.log4j.message.ParameterizedMessage;
-import org.apache.logging.log4j.message.ParameterizedMessageFactory;
 import org.apache.logging.log4j.message.ReusableMessageFactory;
 import org.apache.logging.log4j.message.SimpleMessage;
 import org.apache.logging.log4j.message.StringFormattedMessage;
 import org.apache.logging.log4j.status.StatusLogger;
 import org.apache.logging.log4j.util.Constants;
 import org.apache.logging.log4j.util.LambdaUtil;
-import org.apache.logging.log4j.util.LoaderUtil;
 import org.apache.logging.log4j.util.MessageSupplier;
 import org.apache.logging.log4j.util.PerformanceSensitive;
-import org.apache.logging.log4j.util.PropertiesUtil;
 import org.apache.logging.log4j.util.StackLocatorUtil;
 import org.apache.logging.log4j.util.Strings;
 import org.apache.logging.log4j.util.Supplier;
@@ -87,19 +83,6 @@ public abstract class AbstractLogger implements 
ExtendedLogger, Serializable {
      */
     public static final Marker CATCHING_MARKER = 
MarkerManager.getMarker("CATCHING").setParents(EXCEPTION_MARKER);
 
-    /**
-     * The default MessageFactory class.
-     */
-    public static final Class<? extends MessageFactory> 
DEFAULT_MESSAGE_FACTORY_CLASS =
-            
createClassForProperty(LoggingSystemProperties.LOGGER_MESSAGE_FACTORY_CLASS, 
ReusableMessageFactory.class,
-                    ParameterizedMessageFactory.class);
-
-    /**
-     * The default FlowMessageFactory class.
-     */
-    public static final Class<? extends FlowMessageFactory> 
DEFAULT_FLOW_MESSAGE_FACTORY_CLASS =
-            
createFlowClassForProperty(LoggingSystemProperties.LOGGER_FLOW_MESSAGE_FACTORY_CLASS,
 DefaultFlowMessageFactory.class);
-
     private static final long serialVersionUID = 2L;
 
     private static final String FQCN = AbstractLogger.class.getName();
@@ -119,8 +102,8 @@ public abstract class AbstractLogger implements 
ExtendedLogger, Serializable {
     public AbstractLogger() {
         final String canonicalName = getClass().getCanonicalName();
         this.name = canonicalName != null ? canonicalName : 
getClass().getName();
-        this.messageFactory = createDefaultMessageFactory();
-        this.flowMessageFactory = createDefaultFlowMessageFactory();
+        this.messageFactory = LoggingSystem.getMessageFactory();
+        this.flowMessageFactory = LoggingSystem.getFlowMessageFactory();
         this.logBuilder = new LocalLogBuilder(this);
     }
 
@@ -130,7 +113,7 @@ public abstract class AbstractLogger implements 
ExtendedLogger, Serializable {
      * @param name the logger name
      */
     public AbstractLogger(final String name) {
-        this(name, createDefaultMessageFactory());
+        this(name, LoggingSystem.getMessageFactory());
     }
 
     /**
@@ -141,15 +124,15 @@ public abstract class AbstractLogger implements 
ExtendedLogger, Serializable {
      */
     public AbstractLogger(final String name, final MessageFactory 
messageFactory) {
         this.name = name;
-        this.messageFactory = messageFactory == null ? 
createDefaultMessageFactory() : messageFactory;
-        this.flowMessageFactory = createDefaultFlowMessageFactory();
+        this.messageFactory = messageFactory == null ? 
LoggingSystem.getMessageFactory() : messageFactory;
+        this.flowMessageFactory = LoggingSystem.getFlowMessageFactory();
         this.logBuilder = new LocalLogBuilder(this);
     }
 
     /**
      * Checks that the message factory a logger was created with is the same 
as the given messageFactory. If they are
      * different log a warning to the {@linkplain StatusLogger}. A null 
MessageFactory translates to the default
-     * MessageFactory {@link #DEFAULT_MESSAGE_FACTORY_CLASS}.
+     * MessageFactory {@link LoggingSystem#getMessageFactory()}.
      *
      * @param logger The logger to check
      * @param messageFactory The message factory to check.
@@ -157,18 +140,19 @@ public abstract class AbstractLogger implements 
ExtendedLogger, Serializable {
     public static void checkMessageFactory(final ExtendedLogger logger, final 
MessageFactory messageFactory) {
         final String name = logger.getName();
         final MessageFactory loggerMessageFactory = logger.getMessageFactory();
+        final MessageFactory currentMessageFactory = 
LoggingSystem.getMessageFactory();
         if (messageFactory != null && 
!loggerMessageFactory.equals(messageFactory)) {
             StatusLogger.getLogger().warn(
                     "The Logger {} was created with the message factory {} and 
is now requested with the "
                             + "message factory {}, which may create log events 
with unexpected formatting.", name,
                     loggerMessageFactory, messageFactory);
-        } else if (messageFactory == null && 
!loggerMessageFactory.getClass().equals(DEFAULT_MESSAGE_FACTORY_CLASS)) {
+        } else if (messageFactory == null && loggerMessageFactory != 
currentMessageFactory) {
             StatusLogger
                     .getLogger()
                     .warn("The Logger {} was created with the message factory 
{} and is now requested with a null "
                             + "message factory (defaults to {}), which may 
create log events with unexpected "
                             + "formatting.",
-                            name, loggerMessageFactory, 
DEFAULT_MESSAGE_FACTORY_CLASS.getName());
+                            name, loggerMessageFactory, 
currentMessageFactory.getClass().getName());
         }
     }
 
@@ -201,45 +185,6 @@ public abstract class AbstractLogger implements 
ExtendedLogger, Serializable {
         return messageFactory.newMessage(CATCHING);
     }
 
-    private static Class<? extends MessageFactory> 
createClassForProperty(final String property,
-            final Class<ReusableMessageFactory> 
reusableParameterizedMessageFactoryClass,
-            final Class<ParameterizedMessageFactory> 
parameterizedMessageFactoryClass) {
-        try {
-            final String fallback = Constants.isThreadLocalsEnabled() ? 
reusableParameterizedMessageFactoryClass.getName()
-                    : parameterizedMessageFactoryClass.getName();
-            final String clsName = 
PropertiesUtil.getProperties().getStringProperty(property, fallback);
-            return 
LoaderUtil.loadClass(clsName).asSubclass(MessageFactory.class);
-        } catch (final Throwable t) {
-            return parameterizedMessageFactoryClass;
-        }
-    }
-
-    private static Class<? extends FlowMessageFactory> 
createFlowClassForProperty(final String property,
-            final Class<DefaultFlowMessageFactory> 
defaultFlowMessageFactoryClass) {
-        try {
-            final String clsName = 
PropertiesUtil.getProperties().getStringProperty(property, 
defaultFlowMessageFactoryClass.getName());
-            return 
LoaderUtil.loadClass(clsName).asSubclass(FlowMessageFactory.class);
-        } catch (final Throwable t) {
-            return defaultFlowMessageFactoryClass;
-        }
-    }
-
-    private static MessageFactory createDefaultMessageFactory() {
-        try {
-            return DEFAULT_MESSAGE_FACTORY_CLASS.newInstance();
-        } catch (final InstantiationException | IllegalAccessException e) {
-            throw new IllegalStateException(e);
-        }
-    }
-
-    private static FlowMessageFactory createDefaultFlowMessageFactory() {
-        try {
-            return DEFAULT_FLOW_MESSAGE_FACTORY_CLASS.newInstance();
-        } catch (final InstantiationException | IllegalAccessException e) {
-            throw new IllegalStateException(e);
-        }
-    }
-
     @Override
     public void debug(final Marker marker, final CharSequence message) {
         logIfEnabled(FQCN, Level.DEBUG, marker, message, null);
diff --git 
a/log4j-api/src/main/java/org/apache/logging/log4j/spi/LoggerRegistry.java 
b/log4j-api/src/main/java/org/apache/logging/log4j/spi/LoggerRegistry.java
index 139e33baf0..0e3e156aac 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/spi/LoggerRegistry.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/spi/LoggerRegistry.java
@@ -29,7 +29,6 @@ import org.apache.logging.log4j.message.MessageFactory;
  * Convenience class to be used by {@code LoggerContext} implementations.
  */
 public class LoggerRegistry<T extends ExtendedLogger> {
-    private static final String DEFAULT_FACTORY_KEY = 
AbstractLogger.DEFAULT_MESSAGE_FACTORY_CLASS.getName();
     private final MapFactory<T> factory;
     private final Map<String, Map<String, T>> map;
 
@@ -96,12 +95,16 @@ public class LoggerRegistry<T extends ExtendedLogger> {
         this.map = factory.createOuterMap();
     }
 
+    private static String defaultFactoryKey() {
+        return LoggingSystem.getMessageFactory().getClass().getName();
+    }
+
     private static String factoryClassKey(final Class<? extends 
MessageFactory> messageFactoryClass) {
-        return messageFactoryClass == null ? DEFAULT_FACTORY_KEY : 
messageFactoryClass.getName();
+        return messageFactoryClass == null ? defaultFactoryKey() : 
messageFactoryClass.getName();
     }
 
     private static String factoryKey(final MessageFactory messageFactory) {
-        return messageFactory == null ? DEFAULT_FACTORY_KEY : 
messageFactory.getClass().getName();
+        return messageFactory == null ? defaultFactoryKey() : 
messageFactory.getClass().getName();
     }
 
     /**
@@ -110,7 +113,7 @@ public class LoggerRegistry<T extends ExtendedLogger> {
      * @return The logger with the specified name.
      */
     public T getLogger(final String name) {
-        return getOrCreateInnerMap(DEFAULT_FACTORY_KEY).get(name);
+        return getOrCreateInnerMap(defaultFactoryKey()).get(name);
     }
 
     /**
@@ -150,7 +153,7 @@ public class LoggerRegistry<T extends ExtendedLogger> {
      * @return true if the Logger exists, false otherwise.
      */
     public boolean hasLogger(final String name) {
-        return getOrCreateInnerMap(DEFAULT_FACTORY_KEY).containsKey(name);
+        return getOrCreateInnerMap(defaultFactoryKey()).containsKey(name);
     }
 
     /**
diff --git 
a/log4j-api/src/main/java/org/apache/logging/log4j/spi/LoggingSystem.java 
b/log4j-api/src/main/java/org/apache/logging/log4j/spi/LoggingSystem.java
index 411887f8a4..1228d030a5 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/spi/LoggingSystem.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/spi/LoggingSystem.java
@@ -34,6 +34,11 @@ import java.util.stream.Collectors;
 
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.ThreadContext;
+import org.apache.logging.log4j.message.DefaultFlowMessageFactory;
+import org.apache.logging.log4j.message.FlowMessageFactory;
+import org.apache.logging.log4j.message.MessageFactory;
+import org.apache.logging.log4j.message.ParameterizedMessageFactory;
+import org.apache.logging.log4j.message.ReusableMessageFactory;
 import org.apache.logging.log4j.simple.SimpleLoggerContextFactory;
 import org.apache.logging.log4j.util.Constants;
 import org.apache.logging.log4j.util.Lazy;
@@ -65,8 +70,29 @@ public class LoggingSystem {
     private static final Lazy<LoggingSystem> SYSTEM = 
Lazy.relaxed(LoggingSystem::new);
 
     private final Lock initializationLock = new ReentrantLock();
-    private volatile LoggingProvider provider;
-    private final Lazy<LoggerContextFactory> loggerContextFactorySupplier = 
Lazy.lazy(() -> getProvider().createLoggerContextFactory());
+    private volatile SystemProvider provider;
+    private final Lazy<PropertyEnvironment> environmentLazy = 
Lazy.relaxed(PropertiesUtil::getProperties);
+    private final Lazy<LoggerContextFactory> loggerContextFactoryLazy = 
Lazy.lazy(() -> getProvider().createLoggerContextFactory());
+    private final Lazy<MessageFactory> messageFactoryLazy = 
environmentLazy.map(environment -> {
+        final String className = 
environment.getStringProperty(LOGGER_MESSAGE_FACTORY_CLASS);
+        if (className != null) {
+            final MessageFactory factory = createInstance(className, 
MessageFactory.class);
+            if (factory != null) {
+                return factory;
+            }
+        }
+        return Constants.isThreadLocalsEnabled() ? new 
ReusableMessageFactory() : new ParameterizedMessageFactory();
+    });
+    private final Lazy<FlowMessageFactory> flowMessageFactoryLazy = 
environmentLazy.map(environment -> {
+        final String className = 
environment.getStringProperty(LOGGER_FLOW_MESSAGE_FACTORY_CLASS);
+        if (className != null) {
+            final FlowMessageFactory factory = createInstance(className, 
FlowMessageFactory.class);
+            if (factory != null) {
+                return factory;
+            }
+        }
+        return new DefaultFlowMessageFactory();
+    });
     private Supplier<ThreadContextMap> threadContextMapSupplier = () -> 
getProvider().createContextMap();
     private Supplier<ThreadContextStack> threadContextStackSupplier = () -> 
getProvider().createContextStack();
 
@@ -89,7 +115,7 @@ public class LoggingSystem {
         initializationLock.unlock();
     }
 
-    private LoggingProvider getProvider() {
+    private SystemProvider getProvider() {
         var provider = this.provider;
         if (provider == null) {
             try {
@@ -100,7 +126,7 @@ public class LoggingSystem {
                 }
             } catch (InterruptedException e) {
                 LowLevelLogUtil.logException("Interrupted before Log4j 
Providers could be loaded", e);
-                provider = new LoggingProvider();
+                provider = new SystemProvider();
                 Thread.currentThread().interrupt();
             } finally {
                 releaseInitializationLock();
@@ -109,12 +135,12 @@ public class LoggingSystem {
         return provider;
     }
 
-    private LoggingProvider findProvider() {
+    private SystemProvider findProvider() {
         final SortedMap<Integer, Provider> providers = new TreeMap<>();
         loadDefaultProviders().forEach(p -> providers.put(p.getPriority(), p));
         loadLegacyProviders().forEach(p -> providers.put(p.getPriority(), p));
         if (providers.isEmpty()) {
-            return new LoggingProvider();
+            return new SystemProvider();
         }
         final Provider provider = providers.get(providers.lastKey());
         if (providers.size() > 1) {
@@ -123,11 +149,19 @@ public class LoggingSystem {
             sb.append("Using ").append(provider);
             LowLevelLogUtil.log(sb.toString());
         }
-        return new LoggingProvider(provider);
+        return new SystemProvider(provider);
     }
 
     public void setLoggerContextFactory(final LoggerContextFactory 
loggerContextFactory) {
-        loggerContextFactorySupplier.set(loggerContextFactory);
+        loggerContextFactoryLazy.set(loggerContextFactory);
+    }
+
+    public void setMessageFactory(final MessageFactory messageFactory) {
+        messageFactoryLazy.set(messageFactory);
+    }
+
+    public void setFlowMessageFactory(final FlowMessageFactory 
flowMessageFactory) {
+        flowMessageFactoryLazy.set(flowMessageFactory);
     }
 
     public void setThreadContextMapSupplier(final Supplier<ThreadContextMap> 
threadContextMapSupplier) {
@@ -150,7 +184,15 @@ public class LoggingSystem {
      * requested.
      */
     public static LoggerContextFactory getLoggerContextFactory() {
-        return getInstance().loggerContextFactorySupplier.get();
+        return getInstance().loggerContextFactoryLazy.value();
+    }
+
+    public static MessageFactory getMessageFactory() {
+        return getInstance().messageFactoryLazy.value();
+    }
+
+    public static FlowMessageFactory getFlowMessageFactory() {
+        return getInstance().flowMessageFactoryLazy.value();
     }
 
     /**
@@ -231,36 +273,25 @@ public class LoggingSystem {
         return null;
     }
 
-    private static ThreadContextMap createCustomContextMap(final String 
className) {
-        try {
-            final Class<?> customClass = LoaderUtil.loadClass(className);
-            final Class<? extends ThreadContextMap> contextMapClass = 
customClass.asSubclass(ThreadContextMap.class);
-            return tryInstantiate(contextMapClass);
-        } catch (final ClassNotFoundException | ClassCastException e) {
-            LowLevelLogUtil.logException(String.format("Unable to load custom 
ThreadContextMap class '%s'", className), e);
-            return null;
-        }
-    }
-
-    private static LoggerContextFactory createCustomFactory(final String 
className) {
+    private static <T> T createInstance(final String className, final Class<T> 
type) {
         try {
-            final Class<?> customClass = LoaderUtil.loadClass(className);
-            final Class<? extends LoggerContextFactory> factoryClass = 
customClass.asSubclass(LoggerContextFactory.class);
-            return tryInstantiate(factoryClass);
+            final Class<?> loadedClass = LoaderUtil.loadClass(className);
+            final Class<? extends T> typedClass = loadedClass.asSubclass(type);
+            return tryInstantiate(typedClass);
         } catch (final ClassNotFoundException | ClassCastException e) {
-            LowLevelLogUtil.logException(String.format("Unable to load custom 
LoggerContextFactory class '%s'", className), e);
+            LowLevelLogUtil.logException(String.format("Unable to load %s 
class '%s'", type.getSimpleName(), className), e);
             return null;
         }
     }
 
-    private static class LoggingProvider {
+    private static class SystemProvider {
         private final Provider provider;
 
-        private LoggingProvider() {
+        private SystemProvider() {
             this(null);
         }
 
-        private LoggingProvider(final Provider provider) {
+        private SystemProvider(final Provider provider) {
             this.provider = provider;
         }
 
@@ -268,7 +299,7 @@ public class LoggingSystem {
             final PropertyEnvironment environment = 
PropertiesUtil.getProperties();
             final String customFactoryClass = 
environment.getStringProperty(LogManager.FACTORY_PROPERTY_NAME);
             if (customFactoryClass != null) {
-                final LoggerContextFactory customFactory = 
createCustomFactory(customFactoryClass);
+                final LoggerContextFactory customFactory = 
createInstance(customFactoryClass, LoggerContextFactory.class);
                 if (customFactory != null) {
                     return customFactory;
                 }
@@ -312,7 +343,7 @@ public class LoggingSystem {
             final PropertyEnvironment environment = 
PropertiesUtil.getProperties();
             final String customThreadContextMap = 
environment.getStringProperty(THREAD_CONTEXT_MAP_CLASS);
             if (customThreadContextMap != null) {
-                final ThreadContextMap customContextMap = 
createCustomContextMap(customThreadContextMap);
+                final ThreadContextMap customContextMap = 
createInstance(customThreadContextMap, ThreadContextMap.class);
                 if (customContextMap != null) {
                     return customContextMap;
                 }
diff --git 
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/LoggerTest.java 
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
index db379f6574..c89c44629f 100644
--- 
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
+++ 
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
@@ -16,6 +16,15 @@
  */
 package org.apache.logging.log4j.core;
 
+import java.io.File;
+import java.lang.reflect.Method;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Marker;
@@ -34,21 +43,12 @@ import 
org.apache.logging.log4j.message.ParameterizedMessageFactory;
 import org.apache.logging.log4j.message.SimpleMessage;
 import org.apache.logging.log4j.message.StringFormatterMessageFactory;
 import org.apache.logging.log4j.message.StructuredDataMessage;
-import org.apache.logging.log4j.spi.AbstractLogger;
+import org.apache.logging.log4j.spi.LoggingSystem;
 import org.hamcrest.MatcherAssert;
 import org.junit.jupiter.api.Tag;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.TestInfo;
 
-import java.io.File;
-import java.lang.reflect.Method;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.junit.jupiter.api.Assertions.*;
 
@@ -58,7 +58,7 @@ public class LoggerTest {
     static final String CONFIG = "log4j-test2.xml";
     private static void checkMessageFactory(final MessageFactory 
messageFactory, final Logger testLogger) {
         if (messageFactory == null) {
-            assertEquals(AbstractLogger.DEFAULT_MESSAGE_FACTORY_CLASS, 
testLogger.getMessageFactory().getClass());
+            assertSame(LoggingSystem.getMessageFactory(), 
testLogger.getMessageFactory());
         } else {
             MessageFactory actual = testLogger.getMessageFactory();
             assertEquals(messageFactory, actual);
@@ -509,4 +509,3 @@ public class LoggerTest {
         assertEventCount(events, 1);
     }
 }
-
diff --git 
a/log4j-taglib/src/test/java/org/apache/logging/log4j/taglib/SetLoggerTagTest.java
 
b/log4j-taglib/src/test/java/org/apache/logging/log4j/taglib/SetLoggerTagTest.java
index bc6450d6b2..d795ee4239 100644
--- 
a/log4j-taglib/src/test/java/org/apache/logging/log4j/taglib/SetLoggerTagTest.java
+++ 
b/log4j-taglib/src/test/java/org/apache/logging/log4j/taglib/SetLoggerTagTest.java
@@ -24,6 +24,7 @@ import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.message.MessageFactory;
 import org.apache.logging.log4j.message.StringFormatterMessageFactory;
 import org.apache.logging.log4j.spi.AbstractLogger;
+import org.apache.logging.log4j.spi.LoggingSystem;
 import org.junit.Before;
 import org.junit.Test;
 import org.springframework.mock.web.MockPageContext;
@@ -167,8 +168,7 @@ public class SetLoggerTagTest {
     private static void checkMessageFactory(final String msg, final 
MessageFactory messageFactory,
             final Logger testLogger) {
         if (messageFactory == null) {
-            assertEquals(msg, AbstractLogger.DEFAULT_MESSAGE_FACTORY_CLASS,
-                    testLogger.getMessageFactory().getClass());
+            assertSame(LoggingSystem.getMessageFactory(), 
testLogger.getMessageFactory());
         } else {
             MessageFactory actual = testLogger.getMessageFactory();
             assertEquals(msg, messageFactory, actual);
diff --git 
a/log4j-to-slf4j/src/test/java/org/apache/logging/slf4j/LoggerTest.java 
b/log4j-to-slf4j/src/test/java/org/apache/logging/slf4j/LoggerTest.java
index c54141a4e8..e5c6d5ed0e 100644
--- a/log4j-to-slf4j/src/test/java/org/apache/logging/slf4j/LoggerTest.java
+++ b/log4j-to-slf4j/src/test/java/org/apache/logging/slf4j/LoggerTest.java
@@ -1,20 +1,19 @@
-
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache license, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the license for the specific language governing permissions and
-* limitations under the license.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
 package org.apache.logging.slf4j;
 
 import java.lang.reflect.InvocationTargetException;
@@ -22,20 +21,22 @@ import java.lang.reflect.Proxy;
 import java.util.Date;
 import java.util.List;
 
-import ch.qos.logback.classic.spi.ILoggingEvent;
-import ch.qos.logback.core.testUtil.StringListAppender;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.ThreadContext;
 import org.apache.logging.log4j.message.MessageFactory;
 import org.apache.logging.log4j.message.ParameterizedMessageFactory;
 import org.apache.logging.log4j.message.StringFormatterMessageFactory;
-import org.apache.logging.log4j.spi.AbstractLogger;
+import org.apache.logging.log4j.spi.LoggingSystem;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
 import org.slf4j.MDC;
 
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.testUtil.StringListAppender;
+
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.*;
 import static org.junit.Assert.*;
 
@@ -130,7 +131,7 @@ public class LoggerTest {
 
     private static void checkMessageFactory(final MessageFactory 
messageFactory, final Logger testLogger) {
         if (messageFactory == null) {
-            assertEquals(AbstractLogger.DEFAULT_MESSAGE_FACTORY_CLASS, 
testLogger.getMessageFactory().getClass());
+            assertSame(LoggingSystem.getMessageFactory(), 
testLogger.getMessageFactory());
         } else {
             MessageFactory actual = testLogger.getMessageFactory();
             assertEquals(messageFactory, actual);

Reply via email to