logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1411553 - in /logging/log4j/log4j2/trunk/core/src: main/java/org/apache/logging/log4j/core/appender/ test/java/org/apache/logging/log4j/core/net/ test/resources/
Date Tue, 20 Nov 2012 05:58:32 GMT
Author: rgoers
Date: Tue Nov 20 05:58:31 2012
New Revision: 1411553

URL: http://svn.apache.org/viewvc?rev=1411553&view=rev
Log:
LOG4J2-125 - JMSQueue and JMSTopic Appenders did not allow name to be specified.

Added:
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/JMSQueueAppenderTest.java
      - copied, changed from r1411345, logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/JMSQueueTest.java
    logging/log4j/log4j2/trunk/core/src/test/resources/log4j-jmsqueue.xml
      - copied, changed from r1411345, logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-config.xml
Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/JMSQueueAppender.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/JMSTopicAppender.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/JMSQueueTest.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/JMSTopicTest.java

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/JMSQueueAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/JMSQueueAppender.java?rev=1411553&r1=1411552&r2=1411553&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/JMSQueueAppender.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/JMSQueueAppender.java
Tue Nov 20 05:58:31 2012
@@ -55,6 +55,7 @@ public final class JMSQueueAppender exte
 
     /**
      * Create a JMSQueueAppender.
+     * @param name The name of the Appender.
      * @param factoryName The fully qualified class name of the InitialContextFactory.
      * @param providerURL The URL of the provider to use.
      * @param urlPkgPrefixes A colon-separated list of package prefixes for the class name
of the factory class that
@@ -72,7 +73,8 @@ public final class JMSQueueAppender exte
      * @return The JMSQueueAppender.
      */
     @PluginFactory
-    public static JMSQueueAppender createAppender(@PluginAttr("factoryName") String factoryName,
+    public static JMSQueueAppender createAppender(@PluginAttr("name") String name,
+                                                  @PluginAttr("factoryName") String factoryName,
                                                   @PluginAttr("providerURL") String providerURL,
                                                   @PluginAttr("urlPkgPrefixes") String urlPkgPrefixes,
                                                   @PluginAttr("securityPrincipalName") String
securityPrincipalName,
@@ -84,8 +86,10 @@ public final class JMSQueueAppender exte
                                                   @PluginElement("layout") Layout layout,
                                                   @PluginElement("filter") Filter filter,
                                                   @PluginAttr("suppressExceptions") String
suppress) {
-
-        String name = "JMSQueue" + factoryBindingName + '.' + queueBindingName;
+        if (name == null) {
+            LOGGER.error("No name provided for JMSQueueAppender");
+            return null;
+        }
         boolean handleExceptions = suppress == null ? true : Boolean.valueOf(suppress);
         JMSQueueManager manager = JMSQueueManager.getJMSQueueManager(factoryName, providerURL,
urlPkgPrefixes,
             securityPrincipalName, securityCredentials, factoryBindingName, queueBindingName,
userName, password);

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/JMSTopicAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/JMSTopicAppender.java?rev=1411553&r1=1411552&r2=1411553&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/JMSTopicAppender.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/JMSTopicAppender.java
Tue Nov 20 05:58:31 2012
@@ -55,6 +55,7 @@ public final class JMSTopicAppender exte
 
     /**
      * Create a JMSTopicAppender.
+     * @param name The name of the Appender.
      * @param factoryName The fully qualified class name of the InitialContextFactory.
      * @param providerURL The URL of the provider to use.
      * @param urlPkgPrefixes A colon-separated list of package prefixes for the class name
of the factory class that
@@ -72,7 +73,8 @@ public final class JMSTopicAppender exte
      * @return The JMSTopicAppender.
      */
     @PluginFactory
-    public static JMSTopicAppender createAppender(@PluginAttr("factoryName") String factoryName,
+    public static JMSTopicAppender createAppender(@PluginAttr("name") String name,
+                                                  @PluginAttr("factoryName") String factoryName,
                                                   @PluginAttr("providerURL") String providerURL,
                                                   @PluginAttr("urlPkgPrefixes") String urlPkgPrefixes,
                                                   @PluginAttr("securityPrincipalName") String
securityPrincipalName,
@@ -85,7 +87,10 @@ public final class JMSTopicAppender exte
                                                   @PluginElement("filters") Filter filter,
                                                   @PluginAttr("suppressExceptions") String
suppress) {
 
-        String name = "JMSTopic" + factoryBindingName + '.' + topicBindingName;
+        if (name == null) {
+            LOGGER.error("No name provided for JMSQueueAppender");
+            return null;
+        }
         boolean handleExceptions = suppress == null ? true : Boolean.valueOf(suppress);
         JMSTopicManager manager = JMSTopicManager.getJMSTopicManager(factoryName, providerURL,
urlPkgPrefixes,
             securityPrincipalName, securityCredentials, factoryBindingName, topicBindingName,
userName, password);

Copied: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/JMSQueueAppenderTest.java
(from r1411345, logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/JMSQueueTest.java)
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/JMSQueueAppenderTest.java?p2=logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/JMSQueueAppenderTest.java&p1=logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/JMSQueueTest.java&r1=1411345&r2=1411553&rev=1411553&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/JMSQueueTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/JMSQueueAppenderTest.java
Tue Nov 20 05:58:31 2012
@@ -25,6 +25,9 @@ import org.apache.logging.log4j.core.Log
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.appender.ConsoleAppender;
 import org.apache.logging.log4j.core.appender.JMSQueueAppender;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.logging.log4j.core.config.XMLConfigurationFactory;
 import org.apache.logging.log4j.test.appender.ListAppender;
 import org.apache.logging.log4j.core.filter.CompositeFilter;
 import org.apache.logging.log4j.core.filter.AbstractFilter;
@@ -52,7 +55,7 @@ import static org.junit.Assert.assertTru
 /**
  *
  */
-public class JMSQueueTest {
+public class JMSQueueAppenderTest {
 
     private static final String FACTORY_NAME = "TestQueueConnectionFactory";
     private static final String QUEUE_NAME = "TestQueue";
@@ -60,6 +63,8 @@ public class JMSQueueTest {
     private static Context context;
     private static AbstractJMSReceiver receiver;
 
+    private static final String CONFIG = "log4j-jmsqueue.xml";
+
     LoggerContext ctx = (LoggerContext) LogManager.getContext();
     Logger root = ctx.getLogger("JMSQueueTest");
 
@@ -72,7 +77,7 @@ public class JMSQueueTest {
         context = new InitialContext();
         context.rebind(FACTORY_NAME, new QueueConnectionFactoryImpl() );
         context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
-        ((LoggerContext) LogManager.getContext()).reconfigure();
+        System.setProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
         receiver = new JMSQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
     }
 
@@ -81,64 +86,11 @@ public class JMSQueueTest {
         StatusLogger.getLogger().reset();
     }
 
-    @After
-    public void teardown() {
-        Map<String,Appender> map = root.getAppenders();
-        for (Map.Entry<String, Appender> entry : map.entrySet()) {
-            Appender app = entry.getValue();
-            root.removeAppender(app);
-            app.stop();
-        }
-    }
-
     @Test
-    public void testServer() throws Exception {
-        Filter clientFilter = new MessageFilter(Filter.Result.NEUTRAL, Filter.Result.DENY);
-        Filter serverFilter = new MessageFilter(Filter.Result.DENY, Filter.Result.NEUTRAL);
-        CompositeFilter clientFilters = CompositeFilter.createFilters(new Filter[]{clientFilter});
-        JMSQueueAppender appender = JMSQueueAppender.createAppender(null, null, null, null,
null, FACTORY_NAME,
-                QUEUE_NAME, null, null, null, clientFilters, "true");
-        appender.start();
-        CompositeFilter serverFilters = CompositeFilter.createFilters(new Filter[]{serverFilter});
-        ListAppender listApp = new ListAppender("Events", serverFilters, null, false, false);
-        listApp.start();
-        PatternLayout layout = PatternLayout.createLayout("%m %ex%n", null, null, null);
-        ConsoleAppender console = ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT",
"Console", "true");
-        console.start();
-        Logger serverLogger = ctx.getLogger(JMSTopicReceiver.class.getName());
-        serverLogger.addAppender(console);
-        serverLogger.setAdditive(false);
-
-
-        // set appender on root and set level to debug
-        root.addAppender(listApp);
-        root.addAppender(appender);
-        root.setAdditive(false);
-        root.setLevel(Level.DEBUG);
-        root.debug("This is a test message");
-        Thread.sleep(100);
-        List<LogEvent> events = listApp.getEvents();
-        assertNotNull("No event retrieved", events);
-        assertTrue("No events retrieved", events.size() > 0);
-        assertTrue("Incorrect event", events.get(0).getMessage().getFormattedMessage().equals("This
is a test message"));
-    }
-
-    private class MessageFilter extends AbstractFilter {
-        public MessageFilter(Result onMatch, Result onMismatch) {
-            super(onMatch, onMismatch);
-        }
-
-        @Override
-        public Result filter(LogEvent event) {
-            StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
-            for (StackTraceElement element : stackTrace) {
-                if (element.getMethodName().equals("onMessage")) {
-                    return onMatch;
-                } else if (element.getMethodName().equals("testServer")) {
-                    return onMismatch;
-                }
-            }
-            return onMismatch;
-        }
+    public void testConfiguration() throws Exception {
+        LoggerContext ctx = (LoggerContext) LogManager.getContext();
+        Configuration config = ctx.getConfiguration();
+        Map<String, Appender> appenders = config.getAppenders();
+        assertTrue(appenders.containsKey("JMSQueue"));
     }
 }

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/JMSQueueTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/JMSQueueTest.java?rev=1411553&r1=1411552&r2=1411553&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/JMSQueueTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/JMSQueueTest.java
Tue Nov 20 05:58:31 2012
@@ -96,7 +96,7 @@ public class JMSQueueTest {
         Filter clientFilter = new MessageFilter(Filter.Result.NEUTRAL, Filter.Result.DENY);
         Filter serverFilter = new MessageFilter(Filter.Result.DENY, Filter.Result.NEUTRAL);
         CompositeFilter clientFilters = CompositeFilter.createFilters(new Filter[]{clientFilter});
-        JMSQueueAppender appender = JMSQueueAppender.createAppender(null, null, null, null,
null, FACTORY_NAME,
+        JMSQueueAppender appender = JMSQueueAppender.createAppender("Test", null, null, null,
null, null, FACTORY_NAME,
                 QUEUE_NAME, null, null, null, clientFilters, "true");
         appender.start();
         CompositeFilter serverFilters = CompositeFilter.createFilters(new Filter[]{serverFilter});

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/JMSTopicTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/JMSTopicTest.java?rev=1411553&r1=1411552&r2=1411553&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/JMSTopicTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/JMSTopicTest.java
Tue Nov 20 05:58:31 2012
@@ -96,7 +96,7 @@ public class JMSTopicTest {
         Filter clientFilter = new MessageFilter(Filter.Result.NEUTRAL, Filter.Result.DENY);
         Filter serverFilter = new MessageFilter(Filter.Result.DENY, Filter.Result.NEUTRAL);
         CompositeFilter clientFilters = CompositeFilter.createFilters(new Filter[]{clientFilter});
-        JMSTopicAppender appender = JMSTopicAppender.createAppender(null, null, null, null,
null, FACTORY_NAME,
+        JMSTopicAppender appender = JMSTopicAppender.createAppender("Test", null, null, null,
null, null, FACTORY_NAME,
                 TOPIC_NAME, null, null, null, clientFilters, "true");
         appender.start();
         CompositeFilter serverFilters = CompositeFilter.createFilters(new Filter[]{serverFilter});

Copied: logging/log4j/log4j2/trunk/core/src/test/resources/log4j-jmsqueue.xml (from r1411345,
logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-config.xml)
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/resources/log4j-jmsqueue.xml?p2=logging/log4j/log4j2/trunk/core/src/test/resources/log4j-jmsqueue.xml&p1=logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-config.xml&r1=1411345&r2=1411553&rev=1411553&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-config.xml (original)
+++ logging/log4j/log4j2/trunk/core/src/test/resources/log4j-jmsqueue.xml Tue Nov 20 05:58:31
2012
@@ -16,21 +16,16 @@
  limitations under the License.
 
 -->
-<configuration name="ConfigTest" status="error" packages="org.apache.logging.log4j.test"
+<configuration name="ConfigTest" status="debug" packages="org.apache.logging.log4j.test"
     monitorInterval="5">
   <appenders>
-    <Console name="STDOUT">
+    <JMSQueue name="JMSQueue" factoryBindingName="TestQueueConnectionFactory" queueBindingName="TestQueue">
       <PatternLayout pattern="%m%n"/>
-    </Console>
-    <List name="List">
-    </List>
+    </JMSQueue>
   </appenders>
   <loggers>
-    <logger name="org.apache.test" level="trace" additivity="false">
-      <appender-ref ref="List"/>
-    </logger>
     <root level="error">
-      <appender-ref ref="STDOUT"/>
+      <appender-ref ref="JMSQueue"/>
     </root>
   </loggers>
 </configuration>
\ No newline at end of file



Mime
View raw message