You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ca...@apache.org on 2007/04/21 23:09:43 UTC

svn commit: r531110 - in /logging/log4j/trunk: src/java/org/apache/log4j/ src/java/org/apache/log4j/xml/ tests/ tests/input/xml/ tests/src/java/org/apache/log4j/xml/

Author: carnold
Date: Sat Apr 21 14:09:42 2007
New Revision: 531110

URL: http://svn.apache.org/viewvc?view=rev&rev=531110
Log:
Bug 42094: Add LoggerRepositoryExImpl and PluginConfigurator to log4j 1.3

Added:
    logging/log4j/trunk/src/java/org/apache/log4j/LoggerRepositoryExImpl.java
      - copied unchanged from r531069, logging/sandbox/log4j/component/src/main/java/org/apache/log4j/LoggerRepositoryExImpl.java
    logging/log4j/trunk/src/java/org/apache/log4j/xml/PluginConfigurator.java
    logging/log4j/trunk/tests/input/xml/plugins1.xml
    logging/log4j/trunk/tests/src/java/org/apache/log4j/xml/MockReceiver.java
    logging/log4j/trunk/tests/src/java/org/apache/log4j/xml/PluginConfiguratorTest.java
Modified:
    logging/log4j/trunk/tests/build.xml

Added: logging/log4j/trunk/src/java/org/apache/log4j/xml/PluginConfigurator.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/xml/PluginConfigurator.java?view=auto&rev=531110
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/xml/PluginConfigurator.java (added)
+++ logging/log4j/trunk/src/java/org/apache/log4j/xml/PluginConfigurator.java Sat Apr 21 14:09:42 2007
@@ -0,0 +1,29 @@
+/*
+ * 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.log4j.xml;
+
+/**
+ *  This class is an alias for org.apache.log4j.xml.DOMConfigurator
+ *  provided so Chainsaw can compile against both log4j 1.2
+ *  and log4j 1.3.  In log4j 1.2, configuration of plugins
+ *  requires extending DOMConfigurator.
+ */
+public final class PluginConfigurator extends
+        org.apache.log4j.xml.DOMConfigurator {
+
+}

Modified: logging/log4j/trunk/tests/build.xml
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/tests/build.xml?view=diff&rev=531110&r1=531109&r2=531110
==============================================================================
--- logging/log4j/trunk/tests/build.xml (original)
+++ logging/log4j/trunk/tests/build.xml Sat Apr 21 14:09:42 2007
@@ -346,6 +346,7 @@
       <classpath refid="tests.classpath"/>
       <formatter type="plain" usefile="false"/>
       <test name="org.apache.log4j.xml.DOMTest" />
+      <test name="org.apache.log4j.xml.PluginConfiguratorTest" />
     </junit>
   </target>
 

Added: logging/log4j/trunk/tests/input/xml/plugins1.xml
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/tests/input/xml/plugins1.xml?view=auto&rev=531110
==============================================================================
--- logging/log4j/trunk/tests/input/xml/plugins1.xml (added)
+++ logging/log4j/trunk/tests/input/xml/plugins1.xml Sat Apr 21 14:09:42 2007
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+  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.
+-->
+<!DOCTYPE log4j:configuration >
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">
+   <plugin name="mock1" class="org.apache.log4j.xml.MockReceiver">
+      <param name="Port" value="4560"/>
+      <param name="Host" value="127.0.0.1" />
+   </plugin>
+   <root>
+      <level value="debug"/>
+   </root>
+</log4j:configuration>

Added: logging/log4j/trunk/tests/src/java/org/apache/log4j/xml/MockReceiver.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/tests/src/java/org/apache/log4j/xml/MockReceiver.java?view=auto&rev=531110
==============================================================================
--- logging/log4j/trunk/tests/src/java/org/apache/log4j/xml/MockReceiver.java (added)
+++ logging/log4j/trunk/tests/src/java/org/apache/log4j/xml/MockReceiver.java Sat Apr 21 14:09:42 2007
@@ -0,0 +1,108 @@
+/*
+ * 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.log4j.xml;
+
+import org.apache.log4j.plugins.PluginSkeleton;
+
+/**
+ * Mock receiver used by PluginConfiguratorTest.
+ */
+public final class MockReceiver extends PluginSkeleton {
+    /**
+     * Is active.
+     */
+    private boolean active = false;
+    /**
+     * Host name.
+     */
+    private String host;
+    /**
+     * Port.
+     */
+    private int port = 0;
+
+    /**
+     * Create new instance.
+     */
+    public MockReceiver() {
+        super();
+    }
+
+    /**
+     * Shutdown.
+     */
+    public void shutdown() {
+        active = false;
+    }
+
+    /**
+     * Is plugin active.
+     * @return true if active.
+     */
+    public boolean isActive() {
+        return active;
+    }
+
+    /**
+     * Activate options.
+     */
+    public void activateOptions() {
+        active = true;
+    }
+
+    /**
+      Get the remote host to connect to for logging events.
+      @return host
+     */
+    public String getHost() {
+      return host;
+    }
+
+    /**
+     * Configures the Host property, this will require activateOptions
+     * to be called for this to take effect.
+     * @param remoteHost address of remote host.
+     */
+    public void setHost(final String remoteHost) {
+      this.host = remoteHost;
+    }
+    /**
+      Set the remote host to connect to for logging events.
+     Equivalent to setHost.
+     @param remoteHost address of remote host.
+     */
+    public void setPort(final String remoteHost) {
+      host = remoteHost;
+    }
+
+    /**
+      Get the remote port to connect to for logging events.
+     @return port
+     */
+    public int getPort() {
+      return port;
+    }
+
+    /**
+      Set the remote port to connect to for logging events.
+      @param p port
+     */
+    public void setPort(final int p) {
+      this.port = p;
+    }
+
+}

Added: logging/log4j/trunk/tests/src/java/org/apache/log4j/xml/PluginConfiguratorTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/tests/src/java/org/apache/log4j/xml/PluginConfiguratorTest.java?view=auto&rev=531110
==============================================================================
--- logging/log4j/trunk/tests/src/java/org/apache/log4j/xml/PluginConfiguratorTest.java (added)
+++ logging/log4j/trunk/tests/src/java/org/apache/log4j/xml/PluginConfiguratorTest.java Sat Apr 21 14:09:42 2007
@@ -0,0 +1,61 @@
+/*
+ * 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.log4j.xml;
+
+
+import junit.framework.TestCase;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.spi.LoggerRepositoryEx;
+import org.apache.log4j.plugins.*;
+
+import java.util.List;
+
+/**
+ *
+ * Tests for PluginConfigurator.
+ */
+public final class PluginConfiguratorTest extends TestCase {
+
+    /**
+     * Create new instance.
+     * @param testName test name.
+     */
+    public PluginConfiguratorTest(final String testName) {
+        super(testName);
+    }
+
+    /**
+     * Test parsing a file containing a plugin element.
+     */
+    public void testParse() {
+        PluginConfigurator.configure("input/xml/plugins1.xml");
+        PluginRegistry plugins =
+                ((LoggerRepositoryEx) LogManager.getLoggerRepository()).
+                        getPluginRegistry();
+        assertTrue(plugins.pluginNameExists("mock1"));
+        List receivers = plugins.getPlugins(
+                org.apache.log4j.xml.MockReceiver.class);
+        assertEquals(1, receivers.size());
+        MockReceiver mock1 = (MockReceiver) receivers.get(0);
+        assertEquals("mock1", mock1.getName());
+        assertEquals("127.0.0.1", mock1.getHost());
+        assertEquals(4560, mock1.getPort());
+        assertTrue(mock1.isActive());
+        plugins.stopAllPlugins();
+        assertFalse(mock1.isActive());
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org