logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1420773 - in /logging/log4j/log4j2/trunk: api/src/main/java/org/apache/logging/log4j/message/ api/src/test/java/org/apache/logging/log4j/ core/src/test/java/org/apache/logging/log4j/core/
Date Wed, 12 Dec 2012 15:31:56 GMT
Author: ggregory
Date: Wed Dec 12 15:31:53 2012
New Revision: 1420773

URL: http://svn.apache.org/viewvc?rev=1420773&view=rev
Log:
Add singletons to message factories.

Modified:
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/ParameterizedMessageFactory.java
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/StringFormatterMessageFactory.java
    logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/LoggerTest.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/ParameterizedMessageFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/ParameterizedMessageFactory.java?rev=1420773&r1=1420772&r2=1420773&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/ParameterizedMessageFactory.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/ParameterizedMessageFactory.java
Wed Dec 12 15:31:53 2012
@@ -21,12 +21,20 @@ package org.apache.logging.log4j.message
  * <p>
  * Creates {@link ParameterizedMessage} instances for {@link #newMessage(String, Object...)}.
  * </p>
+ * <p>
+ * This class is immutable.
+ * </p>
  * 
  * @version $Id$
  */
 public class ParameterizedMessageFactory extends AbstractMessageFactory {
 
     /**
+     * Instance of StringFormatterMessageFactory.
+     */
+    public static final ParameterizedMessageFactory INSTANCE = new ParameterizedMessageFactory();
+
+    /**
      * Creates {@link ParameterizedMessage} instances.
      * 
      * @see MessageFactory#newMessage(String, Object...)

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/StringFormatterMessageFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/StringFormatterMessageFactory.java?rev=1420773&r1=1420772&r2=1420773&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/StringFormatterMessageFactory.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/StringFormatterMessageFactory.java
Wed Dec 12 15:31:53 2012
@@ -23,12 +23,20 @@ import java.util.Formatter;
  * <p>
  * Creates {@link StringFormattedMessage} instances for {@link #newMessage(String, Object...)}.
  * </p>
+ * <p>
+ * This class is immutable.
+ * </p>
  * 
  * @version $Id$
  */
 public class StringFormatterMessageFactory extends AbstractMessageFactory {
 
     /**
+     * Instance of StringFormatterMessageFactory.
+     */
+    public static final StringFormatterMessageFactory INSTANCE = new StringFormatterMessageFactory();
+
+    /**
      * Creates {@link StringFormattedMessage} instances.
      * 
      * @see MessageFactory#newMessage(String, Object...)

Modified: logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/LoggerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/LoggerTest.java?rev=1420773&r1=1420772&r2=1420773&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/LoggerTest.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/LoggerTest.java
Wed Dec 12 15:31:53 2012
@@ -108,7 +108,7 @@ public class LoggerTest {
     public void getLogger_Class_ParameterizedMessageFactory() {
         // The TestLogger logger was already created in an instance variable for this class.
         // The message factory is only used when the logger is created.
-        final ParameterizedMessageFactory messageFactory = new ParameterizedMessageFactory();
+        final ParameterizedMessageFactory messageFactory = ParameterizedMessageFactory.INSTANCE;
         final TestLogger testLogger = (TestLogger) LogManager.getLogger(TestParameterizedMessageFactory.class,
                 messageFactory);
         assertNotNull(testLogger);
@@ -122,7 +122,7 @@ public class LoggerTest {
     public void getLogger_Object_ParameterizedMessageFactory() {
         // The TestLogger logger was already created in an instance variable for this class.
         // The message factory is only used when the logger is created.
-        final ParameterizedMessageFactory messageFactory = new ParameterizedMessageFactory();
+        final ParameterizedMessageFactory messageFactory =  ParameterizedMessageFactory.INSTANCE;
         final TestLogger testLogger = (TestLogger) LogManager.getLogger(new TestParameterizedMessageFactory(),
                 messageFactory);
         assertNotNull(testLogger);
@@ -162,7 +162,7 @@ public class LoggerTest {
 
     @Test
     public void getLogger_String_ParameterizedMessageFactory() {
-        final ParameterizedMessageFactory messageFactory = new ParameterizedMessageFactory();
+        final ParameterizedMessageFactory messageFactory =  ParameterizedMessageFactory.INSTANCE;
         final TestLogger testLogger = (TestLogger) LogManager.getLogger("getLogger_String_ParameterizedMessageFactory",
                 messageFactory);
         assertNotNull(testLogger);
@@ -192,7 +192,7 @@ public class LoggerTest {
         assertNotNull(testLogger);
         assertEquals(messageFactory, testLogger.getMessageFactory());
         final TestLogger testLogger2 = (TestLogger) LogManager.getLogger("getLogger_String_MessageFactoryMismatch",
-                new ParameterizedMessageFactory());
+                ParameterizedMessageFactory.INSTANCE);
         //TODO: How to test?
         //This test context always creates new loggers, other test context impls I tried
fail other tests.
         //assertEquals(messageFactory, testLogger2.getMessageFactory());        

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java?rev=1420773&r1=1420772&r2=1420773&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
Wed Dec 12 15:31:53 2012
@@ -129,10 +129,11 @@ public class LoggerTest {
 
     @Test
     public void getLogger_String_MessageFactoryMismatch() {
-        final Logger testLogger =  testMessageFactoryMismatch("getLogger_String_MessageFactoryMismatch",
new StringFormatterMessageFactory(), new ParameterizedMessageFactory());
+        final Logger testLogger = testMessageFactoryMismatch("getLogger_String_MessageFactoryMismatch",
+                new StringFormatterMessageFactory(), ParameterizedMessageFactory.INSTANCE);
         testLogger.debug("%,d", Integer.MAX_VALUE);
         final List<LogEvent> events = app.getEvents();
-        assertTrue("Incorrect number of events. Expected 1, actual " + events.size(), events.size()
== 1);        
+        assertTrue("Incorrect number of events. Expected 1, actual " + events.size(), events.size()
== 1);
         assertEquals(String.format("%,d", Integer.MAX_VALUE), events.get(0).getMessage().getFormattedMessage());
     }
 



Mime
View raw message