Author: psmith
Date: Sat Apr 28 20:50:26 2007
New Revision: 533461

URL: http://svn.apache.org/viewvc?view=rev&rev=533461
Log:
Added JULReceiver that uses the bridge, plus test case.

Test case passes under ant, but not with maven.  Cause unknown as yet.


Added:
    logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/log4j/
    logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/log4j/jul/
    
logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/log4j/jul/JULReceiver.java
    logging/sandbox/juli-to-log4j-bridge/src/test/java/org/apache/log4j/
    logging/sandbox/juli-to-log4j-bridge/src/test/java/org/apache/log4j/jul/
    
logging/sandbox/juli-to-log4j-bridge/src/test/java/org/apache/log4j/jul/JULReceiverTest.java
    logging/sandbox/juli-to-log4j-bridge/src/test/resources/org/
    logging/sandbox/juli-to-log4j-bridge/src/test/resources/org/apache/
    logging/sandbox/juli-to-log4j-bridge/src/test/resources/org/apache/log4j/
    
logging/sandbox/juli-to-log4j-bridge/src/test/resources/org/apache/log4j/jul/
    
logging/sandbox/juli-to-log4j-bridge/src/test/resources/org/apache/log4j/jul/JULReceiverPluginTest.xml

Added: 
logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/log4j/jul/JULReceiver.java
URL: 
http://svn.apache.org/viewvc/logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/log4j/jul/JULReceiver.java?view=auto&rev=533461
==============================================================================
--- 
logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/log4j/jul/JULReceiver.java
 (added)
+++ 
logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/log4j/jul/JULReceiver.java
 Sat Apr 28 20:50:26 2007
@@ -0,0 +1,35 @@
+package org.apache.log4j.jul;
+
+import org.apache.log4j.plugins.Plugin;
+import org.apache.log4j.plugins.PluginSkeleton;
+import org.apache.logging.julbridge.JULLevelConverter;
+import org.apache.logging.julbridge.JULLog4jBridge;
+import org.apache.logging.julbridge.JULLog4jEventConverter;
+
+public class JULReceiver extends PluginSkeleton implements Plugin{
+
+    private String levelConverterClassName;
+    
+    public void shutdown() {
+        JULLog4jBridge.repatriate();
+        
+    }
+
+    public void activateOptions() {
+        JULLevelConverter converter = 
JULLog4jEventConverter.DEFAULT_LEVEL_CONVERTER;
+        if (levelConverterClassName!=null) {
+            Class clazz = null;
+            try {
+                clazz = Class.forName(levelConverterClassName);
+                converter = (JULLevelConverter) clazz.newInstance();
+            } catch (Exception e) {
+                getLogger().error(
+                        "Failed to create converter class " + 
levelConverterClassName + "'", e);
+                return;
+            }
+        }
+        JULLog4jBridge.assimilate(getLoggerRepository(), converter);
+        active = true;
+    }
+
+}

Added: 
logging/sandbox/juli-to-log4j-bridge/src/test/java/org/apache/log4j/jul/JULReceiverTest.java
URL: 
http://svn.apache.org/viewvc/logging/sandbox/juli-to-log4j-bridge/src/test/java/org/apache/log4j/jul/JULReceiverTest.java?view=auto&rev=533461
==============================================================================
--- 
logging/sandbox/juli-to-log4j-bridge/src/test/java/org/apache/log4j/jul/JULReceiverTest.java
 (added)
+++ 
logging/sandbox/juli-to-log4j-bridge/src/test/java/org/apache/log4j/jul/JULReceiverTest.java
 Sat Apr 28 20:50:26 2007
@@ -0,0 +1,48 @@
+package org.apache.log4j.jul;
+
+import java.net.URL;
+
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+import org.apache.log4j.LoggerRepositoryExImpl;
+import org.apache.log4j.plugins.PluginConfigurator;
+import org.apache.log4j.spi.LoggerRepository;
+import org.apache.log4j.spi.RepositorySelector;
+import org.apache.logging.julbridge.MockAppender;
+
+import junit.framework.TestCase;
+
+public class JULReceiverTest extends TestCase {
+
+    private final Object repositorySelectorGuard = new Object();
+    private MockAppender mockAppender = new MockAppender();
+    final LoggerRepository repositoryExImpl = new 
LoggerRepositoryExImpl(LogManager
+            .getLoggerRepository());
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        LogManager.resetConfiguration();
+        LogManager.setRepositorySelector(new RepositorySelector() {
+
+            public LoggerRepository getLoggerRepository() {
+                return repositoryExImpl;
+            }
+        }, repositorySelectorGuard);
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testJULReceiverPluginConfiguration() {
+        URL resource = 
this.getClass().getResource("JULReceiverPluginTest.xml");
+         PluginConfigurator.configure(resource);
+
+        Logger.getRootLogger().addAppender(mockAppender);
+        java.util.logging.Logger juliLogger = 
java.util.logging.Logger.getLogger("foo");
+        juliLogger.info("boo");
+        assertEquals("Should have received 1 event: ", 1, 
mockAppender.observedLoggingEvents.size());
+
+    }
+
+}

Added: 
logging/sandbox/juli-to-log4j-bridge/src/test/resources/org/apache/log4j/jul/JULReceiverPluginTest.xml
URL: 
http://svn.apache.org/viewvc/logging/sandbox/juli-to-log4j-bridge/src/test/resources/org/apache/log4j/jul/JULReceiverPluginTest.xml?view=auto&rev=533461
==============================================================================
--- 
logging/sandbox/juli-to-log4j-bridge/src/test/resources/org/apache/log4j/jul/JULReceiverPluginTest.xml
 (added)
+++ 
logging/sandbox/juli-to-log4j-bridge/src/test/resources/org/apache/log4j/jul/JULReceiverPluginTest.xml
 Sat Apr 28 20:50:26 2007
@@ -0,0 +1,25 @@
+<?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 SYSTEM 
'http://logging.apache.org/log4j/log4j.dtd'>
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"; 
debug="true">
+   <plugin name="julreceiver" class="org.apache.log4j.jul.JULReceiver">
+   </plugin>
+   <root>
+      <level value="debug"/>
+   </root>
+</log4j:configuration>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to