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 ps...@apache.org on 2007/04/25 06:53:26 UTC

svn commit: r532195 - in /logging/sandbox/juli-to-log4j-bridge: ./ src/main/java/org/apache/logging/julibridge/ src/test/java/org/apache/logging/julibridge/

Author: psmith
Date: Tue Apr 24 21:53:24 2007
New Revision: 532195

URL: http://svn.apache.org/viewvc?view=rev&rev=532195
Log:
Added 'assimilate' function that completely takes over the juli
logging system.  This mechanism uses a juli Handler
implementation, since that is the only way to gain
access to all LogRecords coming into the Hierachy.  
Filter's only gain access to LogRecords specific to a Logger
and don't observer LogRecords from child Loggers.

Changed the 'bridge' methods so that existing Filters set
on specific loggers are delegated to rather than being overwritten.

Modified the pom.xml to add dependency on log4j 1.2.15 
due to the LocationInfo recent changes.

Added:
    logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/logging/julibridge/JuliBridgeHandler.java
Modified:
    logging/sandbox/juli-to-log4j-bridge/   (props changed)
    logging/sandbox/juli-to-log4j-bridge/pom.xml
    logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/logging/julibridge/JuliBridgeFilter.java
    logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/logging/julibridge/JuliLevelConverter.java
    logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/logging/julibridge/JuliLog4jBridge.java
    logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/logging/julibridge/JuliLog4jEventConverter.java
    logging/sandbox/juli-to-log4j-bridge/src/test/java/org/apache/logging/julibridge/JuliLog4jBridgeTest.java
    logging/sandbox/juli-to-log4j-bridge/src/test/java/org/apache/logging/julibridge/TestLogPosting.java

Propchange: logging/sandbox/juli-to-log4j-bridge/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Apr 24 21:53:24 2007
@@ -0,0 +1 @@
+target

Modified: logging/sandbox/juli-to-log4j-bridge/pom.xml
URL: http://svn.apache.org/viewvc/logging/sandbox/juli-to-log4j-bridge/pom.xml?view=diff&rev=532195&r1=532194&r2=532195
==============================================================================
--- logging/sandbox/juli-to-log4j-bridge/pom.xml (original)
+++ logging/sandbox/juli-to-log4j-bridge/pom.xml Tue Apr 24 21:53:24 2007
@@ -8,7 +8,7 @@
     <dependency>
       <groupId>log4j</groupId>
       <artifactId>log4j</artifactId>
-      <version>1.2.14</version>
+      <version>1.2.15</version>
     </dependency>
     <dependency>
       <groupId>junit</groupId>
@@ -100,7 +100,7 @@
           <dependency>
             <groupId>log4j</groupId>
             <artifactId>log4j</artifactId>
-            <version>1.2.14</version>
+            <version>1.2.15</version>
           </dependency>
         </dependencies>
       </plugin>

Modified: logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/logging/julibridge/JuliBridgeFilter.java
URL: http://svn.apache.org/viewvc/logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/logging/julibridge/JuliBridgeFilter.java?view=diff&rev=532195&r1=532194&r2=532195
==============================================================================
--- logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/logging/julibridge/JuliBridgeFilter.java (original)
+++ logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/logging/julibridge/JuliBridgeFilter.java Tue Apr 24 21:53:24 2007
@@ -1,18 +1,12 @@
 /*
- * 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.julibridge;
 
@@ -24,30 +18,39 @@
 import org.apache.log4j.spi.LoggingEvent;
 
 /**
- * {@link Filter} implementation that posts any {@link LogRecord} received
- * to a specified {@link Logger}, using the {@link JuliLevelConverter} class
- * to map to a {@link Level}.
- * 
+ * <p>
+ * {@link Filter} implementation that posts any {@link LogRecord} received to a specified
+ * {@link Logger}, using the {@link JuliLevelConverter} class to map to a {@link Level}.
+ * </p>
+ * <p>
  * Once a {@link LogRecord} is received, it is 'appended' to all Appenders.
+ * </p>
+ * <p>
+ * If a non-null existing Filter is provided to this class, then this instance is used to return the
+ * true/false value the {@link Filter#isLoggable(LogRecord)} interface requires. If a null
+ * value is provided, <code>true</code> is returned to mimic the default
+ * behaviour of a Logger not having Filter configured.
+ * </p>
  * 
  * @author psmith
- *
  */
-public class JuliBridgeFilter implements Filter{
+class JuliBridgeFilter implements Filter {
 
     private final Logger loggerToPostTo;
     private final JuliLog4jEventConverter converter;
-    
-    public JuliBridgeFilter(Logger loggerToPostTo, JuliLog4jEventConverter converter) {
+    private final Filter existingJuliFilter;
+
+    public JuliBridgeFilter(final Filter existingJuliFilter, Logger loggerToPostTo,
+            JuliLog4jEventConverter converter) {
+        this.existingJuliFilter = existingJuliFilter;
         this.loggerToPostTo = loggerToPostTo;
         this.converter = converter;
     }
-    
 
     public boolean isLoggable(LogRecord record) {
         LoggingEvent event = converter.convert(record);
         loggerToPostTo.callAppenders(event);
-        return false;
+        return (existingJuliFilter != null ? existingJuliFilter.isLoggable(record) : true);
     }
 
 }

Added: logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/logging/julibridge/JuliBridgeHandler.java
URL: http://svn.apache.org/viewvc/logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/logging/julibridge/JuliBridgeHandler.java?view=auto&rev=532195
==============================================================================
--- logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/logging/julibridge/JuliBridgeHandler.java (added)
+++ logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/logging/julibridge/JuliBridgeHandler.java Tue Apr 24 21:53:24 2007
@@ -0,0 +1,43 @@
+package org.apache.logging.julibridge;
+
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.spi.LoggerRepository;
+import org.apache.log4j.spi.LoggingEvent;
+
+
+/**
+ * An implementation of {@link Handler} that converts the {@link LogRecord}
+ * into a {@link LoggingEvent} and posts it to a duplicately named
+ * {@link Logger} in the log4j system.
+ * 
+ * @author psmith
+ *
+ */
+class JuliBridgeHandler extends Handler{
+
+    private final LoggerRepository repository;
+    private final JuliLog4jEventConverter converter;
+    
+    public JuliBridgeHandler(LoggerRepository repository, JuliLog4jEventConverter converter) {
+        this.repository = repository;
+        this.converter = converter;
+    }
+    
+
+    public void close() throws SecurityException {
+        
+    }
+
+    public void flush() {
+        
+    }
+
+    public void publish(LogRecord record) {
+        LoggingEvent event = converter.convert(record);
+        repository.getLogger(record.getLoggerName()).callAppenders(event);
+    }
+
+}

Modified: logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/logging/julibridge/JuliLevelConverter.java
URL: http://svn.apache.org/viewvc/logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/logging/julibridge/JuliLevelConverter.java?view=diff&rev=532195&r1=532194&r2=532195
==============================================================================
--- logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/logging/julibridge/JuliLevelConverter.java (original)
+++ logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/logging/julibridge/JuliLevelConverter.java Tue Apr 24 21:53:24 2007
@@ -36,4 +36,12 @@
      * @return
      */
     public Level convertJuliLevel(java.util.logging.Level juliLevel);
+    
+    /**
+     * Converts a log4j {@link Level} into a juli {@link java.util.logging.Level}.
+     * 
+     * @param log4jLevel
+     * @return
+     */
+    public java.util.logging.Level convertLog4jLevel(Level log4jLevel);
 }

Modified: logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/logging/julibridge/JuliLog4jBridge.java
URL: http://svn.apache.org/viewvc/logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/logging/julibridge/JuliLog4jBridge.java?view=diff&rev=532195&r1=532194&r2=532195
==============================================================================
--- logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/logging/julibridge/JuliLog4jBridge.java (original)
+++ logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/logging/julibridge/JuliLog4jBridge.java Tue Apr 24 21:53:24 2007
@@ -1,72 +1,119 @@
 /*
- * 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.julibridge;
 
+import java.util.logging.Filter;
+import java.util.logging.Level;
+
 import org.apache.log4j.LogManager;
 import org.apache.log4j.Logger;
 import org.apache.log4j.spi.LoggerRepository;
 
 /**
- * Helper class that creates bridge filters between java.util.logging.Loggers
- * and an equivalent log4j Logger.
+ * <p>
+ * Helper class that creates bridge filters between java.util.logging.Loggers and an equivalent
+ * log4j Logger.
+ * </p>
+ * <p>
+ * The <code>bridge</code>-style method calls use a {@link Filter} implementation that tries to
+ * minimise interference with the existing <code>java.util.logging</code> configuration, but can
+ * only bridge specific named loggers, and is not able to bridge child loggers automatically. Any
+ * Logger that is bridged that contains an existing Filter instance is delegated to when deciding if
+ * the LogRecord should continue in the java.util.logging framework, even though the bridge posts
+ * the LogRecord into log4j regardless. If there was no existing Filter defined for the bridged
+ * Logger, then the bridging Filter returns 'true' to mimic the default behaviour of not having a
+ * Filter defined.
+ * </p>
+ * <p>
+ * The <code>assimilate</code>-style methods are much more dramatic, in that they are designed to
+ * completely take over the juli-logging, and route all events into log4j. This mechanism resets the
+ * java.util.logging framework configuration to it's default state, which has default {@link Level}
+ * configured at INFO, and then configures the root juli Logger with the matching Level that the
+ * provided LoggerRepository has been configured. You should, therefore, assimilate the juli logging
+ * system after the log4j system has been properly configured. You should consider whether the
+ * default {@link JuliLevelConverter} is appropriate to your needs, you may optionally provide your
+ * own conversion instance to map the 2 Level classes.
+ * </p>
+ * <p>
+ * The assimilate approach is very useful for the general case where you wish to forget about juli
+ * logging and use the flexibility of the log4j system. There is an ever so slightly higher cost in
+ * routing the event into log4j using this approach because each LogRecord received must
+ * lookup a named {@link Logger}.  The <code>bridge</code>-style approach is slightly faster 
+ * because the specifically requested logger name is looked-up on construction and re-used.
+ * Generally though, the slight performance hit is not worth the inflexibility of having
+ * to specify each and every Logger you want to bridge.
+ * </p>
  * 
+ * @see JuliLevelConverter
+ * @see JuliLog4jEventConverter#DEFAULT_LEVEL_CONVERTER
  * @author psmith
- *
  */
 public class JuliLog4jBridge {
 
-    private static final Logger LOG = Logger.getLogger(JuliLog4jBridge.class);
-
-//    TODO create a Timer that automatically bridges logger names as they arrive.
-    
-    
     /**
-     * Convenience method that gathers the default LoggerRepository and uses a 
-     * default Level Converter implemenation.
+     * Convenience method that gathers the default LoggerRepository and uses a default Level
+     * Converter implemenation.
      * 
      * @param juliLoggerName
      */
     public static void bridgeJuliLogger(String juliLoggerName) {
-        bridgeJuliLogger(juliLoggerName, LogManager.getLoggerRepository(), JuliLog4jEventConverter.DEFAULT_LEVEL_CONVERTER);
+        bridgeJuliLogger(juliLoggerName, LogManager.getLoggerRepository(),
+                JuliLog4jEventConverter.DEFAULT_LEVEL_CONVERTER);
     }
 
-    
     public static void bridgeJuliLogger(String juliLoggerName, LoggerRepository repository) {
-        bridgeJuliLogger(juliLoggerName, repository, JuliLog4jEventConverter.DEFAULT_LEVEL_CONVERTER);
+        bridgeJuliLogger(juliLoggerName, repository,
+                JuliLog4jEventConverter.DEFAULT_LEVEL_CONVERTER);
     }
-    
+
     /**
-     * Creates a bridge between the named java.util.logging Logger name,
-     * and an equivalent inside the log4j LoggerRepository, using
-     * the provided level converter class.
-     * 
-     * If the juli Logger already has a configured Filter, then it is replaced 
-     * by this bridge, and a WARN level event is triggered on the JuliLog4jBridge own Logger
+     * Creates a bridge between the named java.util.logging Logger name, and an equivalent inside
+     * the log4j LoggerRepository, using the provided level converter class. If the juli Logger
+     * already has a configured Filter, then it is replaced by this bridge, and a WARN level event
+     * is triggered on the JuliLog4jBridge own Logger
      * 
      * @param juliLoggerName
      * @param repository
      */
-    public static void bridgeJuliLogger(String juliLoggerName, LoggerRepository repository, JuliLevelConverter levelConverter) {
+    public static void bridgeJuliLogger(String juliLoggerName, LoggerRepository repository,
+            JuliLevelConverter levelConverter) {
         Logger log4jLogger = repository.getLogger(juliLoggerName);
         java.util.logging.Logger juliLogger = java.util.logging.Logger.getLogger(juliLoggerName);
 
-        if(juliLogger.getFilter()!=null) {
-            LOG.warn("The '" + juliLoggerName + "' java.util.logging.Logger already has a filter class set, and is being replaced with a log4j-bridge impl: " + juliLogger.getFilter().toString());
-        }
-        juliLogger.setFilter(new JuliBridgeFilter(log4jLogger, new JuliLog4jEventConverter(repository, levelConverter)));
+        juliLogger.setFilter(new JuliBridgeFilter(juliLogger.getFilter(), log4jLogger,
+                new JuliLog4jEventConverter(repository, levelConverter)));
     }
+
+    /**
+     * Completely take over the underlying java.logging sub-system. Any existing java.logging
+     * configuration is reset, and a top level Handler is registered that gathers all LogRecords and
+     * converts them into log4j LoggingEvents.
+     */
+    public static void assimilate(LoggerRepository repository, JuliLevelConverter levelConverter) {
+
+        java.util.logging.LogManager.getLogManager().reset();
+
+        java.util.logging.Logger.getLogger("").setLevel(
+                levelConverter.convertLog4jLevel(repository.getThreshold()));
+        java.util.logging.Logger.getLogger("").addHandler(
+                new JuliBridgeHandler(repository, new JuliLog4jEventConverter(repository,
+                        levelConverter)));
+    }
+
+    public static void assimilate(LoggerRepository repository) {
+        assimilate(repository, JuliLog4jEventConverter.DEFAULT_LEVEL_CONVERTER);
+    }
+
+    public static void assimilate() {
+        assimilate(LogManager.getLoggerRepository());
+    }
+
 }

Modified: logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/logging/julibridge/JuliLog4jEventConverter.java
URL: http://svn.apache.org/viewvc/logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/logging/julibridge/JuliLog4jEventConverter.java?view=diff&rev=532195&r1=532194&r2=532195
==============================================================================
--- logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/logging/julibridge/JuliLog4jEventConverter.java (original)
+++ logging/sandbox/juli-to-log4j-bridge/src/main/java/org/apache/logging/julibridge/JuliLog4jEventConverter.java Tue Apr 24 21:53:24 2007
@@ -1,45 +1,35 @@
 /*
- * 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.julibridge;
 
+import java.util.Properties;
 import java.util.logging.LogRecord;
 
-import org.apache.log4j.Category;
 import org.apache.log4j.Level;
 import org.apache.log4j.LogManager;
 import org.apache.log4j.Logger;
-import org.apache.log4j.Priority;
+import org.apache.log4j.spi.LocationInfo;
 import org.apache.log4j.spi.LoggerRepository;
 import org.apache.log4j.spi.LoggingEvent;
-
+import org.apache.log4j.spi.ThrowableInformation;
 
 /**
- * 
- * Converter class that can convert a {@link LogRecord} instance
- * into a log4j {@link LoggingEvent}.
+ * Converter class that can convert a {@link LogRecord} instance into a log4j {@link LoggingEvent}.
  * 
  * @author psmith
- *
  */
 public class JuliLog4jEventConverter {
 
     /**
      * A default implementation of a converter that converts:
-     * 
      * <li> FINEST -> TRACE</li>
      * <li> FINER, FINE -> DEBUG</li>
      * <li> INFO -> INFO</li>
@@ -47,7 +37,6 @@
      * <li> SEVERE -> ERROR</li>
      * <li> ALL -> ALL</li>
      * <li> OFF -> OFF</li>
-     * 
      * Anything else is defaulted to DEBUG
      */
     private static final class DefaultLevelConverter implements JuliLevelConverter {
@@ -74,6 +63,27 @@
             return Level.DEBUG;
 
         }
+
+        public java.util.logging.Level convertLog4jLevel(Level log4jLevel) {
+            if (log4jLevel.equals(Level.TRACE)) {
+                return java.util.logging.Level.FINEST;
+            } else if (log4jLevel.equals(Level.DEBUG)) {
+                return java.util.logging.Level.FINER;
+            } else if (log4jLevel.equals(Level.INFO)) {
+                return java.util.logging.Level.INFO;
+            } else if (log4jLevel.equals(Level.WARN)) {
+                return java.util.logging.Level.WARNING;
+            } else if (log4jLevel.equals(Level.ERROR)) {
+                return java.util.logging.Level.SEVERE;
+            } else if (log4jLevel.equals(Level.FATAL)) {
+                return java.util.logging.Level.SEVERE;
+            } else if (log4jLevel.equals(Level.ALL)) {
+                return java.util.logging.Level.ALL;
+            } else if (log4jLevel.equals(Level.OFF)) {
+                return java.util.logging.Level.OFF;
+            }
+            return java.util.logging.Level.FINE;
+        }
     }
 
     private final LoggerRepository repository;
@@ -82,8 +92,8 @@
     public static final JuliLevelConverter DEFAULT_LEVEL_CONVERTER = new DefaultLevelConverter();
 
     /**
-     * Creates a default converter implementation that uses the default {@link LoggerRepository}, ad the default
-     * {@link JuliLevelConverter}
+     * Creates a default converter implementation that uses the default {@link LoggerRepository},
+     * ad the default {@link JuliLevelConverter}
      */
     public JuliLog4jEventConverter() {
         this(LogManager.getLoggerRepository());
@@ -99,49 +109,30 @@
     }
 
     /**
-     * Converts a {@link LogRecord} class into a {@link LoggingEvent} instance mapping the loggernames
-     * identically.
+     * Converts a {@link LogRecord} class into a {@link LoggingEvent} instance mapping the
+     * loggernames identically.
      * 
-     * @param record to convert
+     * @param record
+     *            to convert
      * @return converted {@link LoggingEvent}
      */
     public LoggingEvent convert(LogRecord record) {
         String loggerName = record.getLoggerName();
         Logger logger = repository.getLogger(loggerName);
-        LoggingEvent event = new ConvertedLoggingEvent(loggerName, logger, record.getMillis(),
-                levelConverter.convertJuliLevel(record.getLevel()), record.getMessage(), record
-                        .getThrown()
+        String sourceClassName = record.getSourceClassName();
+        String sourceMethodName = record.getSourceMethodName();
+        LocationInfo locationInfo = new LocationInfo("?", sourceClassName, sourceMethodName, "?");
+        String ndc = null;
+        // TODO get thread name properly.
+        String threadName = String.valueOf(record.getThreadID());
+        ThrowableInformation throwableInformation = record.getThrown() == null ? null
+                : new ThrowableInformation(record.getThrown());
+        LoggingEvent event = new LoggingEvent(loggerName, logger, record.getMillis(),
+                levelConverter.convertJuliLevel(record.getLevel()), record.getMessage(),
+                threadName, throwableInformation, ndc, locationInfo, new Properties()
 
         );
 
-        // TODO LocationInfo
-
         return event;
     }
-
-    /**
-     * This class is unfortunately required because not all LoggingEvent 
-     * properties can be modified in log4j 1.2.
-     * 
-     */
-    private static class ConvertedLoggingEvent extends LoggingEvent {
-
-        // private LocationInfo locationInfo = null;
-        public ConvertedLoggingEvent(String fqnOfCategoryClass, Category logger, long timeStamp,
-                Priority level, Object message, Throwable throwable
-
-        ) {
-            super(fqnOfCategoryClass, logger, timeStamp, level, message, throwable);
-
-        }
-        //
-        // public LocationInfo getLocationInformation() {
-        //            
-        // if(locationInfo == null) {
-        // locationInfo = new LocationInfo(this.fqnOfCategoryClass, )
-        // }
-        // }
-
-    }
-
 }

Modified: logging/sandbox/juli-to-log4j-bridge/src/test/java/org/apache/logging/julibridge/JuliLog4jBridgeTest.java
URL: http://svn.apache.org/viewvc/logging/sandbox/juli-to-log4j-bridge/src/test/java/org/apache/logging/julibridge/JuliLog4jBridgeTest.java?view=diff&rev=532195&r1=532194&r2=532195
==============================================================================
--- logging/sandbox/juli-to-log4j-bridge/src/test/java/org/apache/logging/julibridge/JuliLog4jBridgeTest.java (original)
+++ logging/sandbox/juli-to-log4j-bridge/src/test/java/org/apache/logging/julibridge/JuliLog4jBridgeTest.java Tue Apr 24 21:53:24 2007
@@ -16,39 +16,116 @@
  */
 package org.apache.logging.julibridge;
 
+import java.util.logging.Level;
+
+import junit.framework.TestCase;
+
 import org.apache.log4j.LogManager;
 import org.apache.log4j.Logger;
+import org.apache.log4j.spi.LocationInfo;
 import org.apache.log4j.spi.LoggingEvent;
 
-import junit.framework.TestCase;
-
 public class JuliLog4jBridgeTest extends TestCase {
 
+    private static final String PARENT_LOGGER = "foo";
+    private static final String LOGGER_NAME = PARENT_LOGGER + ".beep";
+    private MockAppender mockAppender;
+    private java.util.logging.Logger juliLogger;
+    private java.util.logging.Logger parentLogger;
+    private java.util.logging.Logger juliRootLogger;
+    
+
     protected void setUp() throws Exception {
         LogManager.resetConfiguration();
         java.util.logging.LogManager.getLogManager().reset();
+    
+        mockAppender = new MockAppender();
+        Logger.getRootLogger().addAppender(mockAppender);
+        juliLogger = java.util.logging.Logger.getLogger(LOGGER_NAME);
+        parentLogger = java.util.logging.Logger.getLogger(PARENT_LOGGER);
+        juliRootLogger = java.util.logging.Logger.getLogger("");
+        
     }
 
     protected void tearDown() throws Exception {
         super.tearDown();
+        mockAppender = null;
+        /*
+         * It's pretty dumb, but  java.util.logging.LogManager.getLogManager().reset();
+         * does NOT remove any Filter set
+         */
+        juliLogger.setFilter(null);
     }
 
     public void testBridgeJuliLogger() {
-        MockAppender mockAppender = new MockAppender();
-        Logger.getRootLogger().addAppender(mockAppender);
         
-        java.util.logging.Logger juliLogger = java.util.logging.Logger.getLogger("foo");
         juliLogger.warning("boo");
         
         assertEquals("Shouldn't expect a bridged event", 0, mockAppender.observedLoggingEvents.size());
-        JuliLog4jBridge.bridgeJuliLogger("foo");
+        JuliLog4jBridge.bridgeJuliLogger(LOGGER_NAME);
      
         juliLogger.warning("boo2");
         
         assertEquals(1, mockAppender.observedLoggingEvents.size());
         assertEquals("boo2", ((LoggingEvent)mockAppender.observedLoggingEvents.get(0)).getMessage());
         
-      
+    }
+    
+    public void testLocationInfo(){
+        JuliLog4jBridge.bridgeJuliLogger(LOGGER_NAME);
+        juliLogger.logp(Level.INFO, "com.mycompany.MyClass", "doBar", "something");
+
+        assertEquals(1, mockAppender.observedLoggingEvents.size());
+        LoggingEvent loggingEvent = ((LoggingEvent)mockAppender.observedLoggingEvents.get(0));
+        assertEquals(org.apache.log4j.Level.INFO, loggingEvent.getLevel());
+        assertEquals("something", loggingEvent.getMessage());
+
+        LocationInfo locationInformation = loggingEvent.getLocationInformation();
+        assertNotNull(locationInformation);
+        assertNotNull(locationInformation.getClassName());
+        assertNotNull(locationInformation.getMethodName());
+        
+        assertFalse("Class name should not be '?'","?".equals(locationInformation.getClassName()));
+        assertFalse("Method name should not be '?'","?".equals(locationInformation.getMethodName()));
+        
+        
+        
+    }
+    
+    public void testAbsorbedIntoTheLog4jCollective(){
+        JuliLog4jBridge.assimilate();
+        
+        juliLogger.logp(Level.INFO, "com.mycompany.MyClass", "doBar", "something");
+
+        assertEquals(1, mockAppender.observedLoggingEvents.size());
+        LoggingEvent loggingEvent = ((LoggingEvent)mockAppender.observedLoggingEvents.get(0));
+        assertEquals(org.apache.log4j.Level.INFO, loggingEvent.getLevel());
+        assertEquals("something", loggingEvent.getMessage());
+
+        LocationInfo locationInformation = loggingEvent.getLocationInformation();
+        assertNotNull(locationInformation);
+        assertNotNull(locationInformation.getClassName());
+        assertNotNull(locationInformation.getMethodName());
+        
+        assertFalse("Class name should not be '?'","?".equals(locationInformation.getClassName()));
+        assertFalse("Method name should not be '?'","?".equals(locationInformation.getMethodName()));
+        
+        parentLogger.log(Level.INFO, "Hello World");
+        assertEquals(2, mockAppender.observedLoggingEvents.size());
+        loggingEvent = ((LoggingEvent)mockAppender.observedLoggingEvents.get(1));
+        assertEquals(org.apache.log4j.Level.INFO, loggingEvent.getLevel());
+        assertEquals("Hello World", loggingEvent.getMessage());
+        
+    }
+    public void testJuliLevelConfigurationChanges(){
+        assertEquals(Level.INFO, juliRootLogger.getLevel());
+        
+        LogManager.getLoggerRepository().setThreshold(org.apache.log4j.Level.WARN);
+        
+        JuliLog4jBridge.assimilate();
+        
+        assertEquals(Level.WARNING, juliRootLogger.getLevel());
+        
         
     }
 

Modified: logging/sandbox/juli-to-log4j-bridge/src/test/java/org/apache/logging/julibridge/TestLogPosting.java
URL: http://svn.apache.org/viewvc/logging/sandbox/juli-to-log4j-bridge/src/test/java/org/apache/logging/julibridge/TestLogPosting.java?view=diff&rev=532195&r1=532194&r2=532195
==============================================================================
--- logging/sandbox/juli-to-log4j-bridge/src/test/java/org/apache/logging/julibridge/TestLogPosting.java (original)
+++ logging/sandbox/juli-to-log4j-bridge/src/test/java/org/apache/logging/julibridge/TestLogPosting.java Tue Apr 24 21:53:24 2007
@@ -42,7 +42,7 @@
     }
     
     public void testBasicObservedEvent() {
-        juliLog.setFilter(new JuliBridgeFilter(log, new JuliLog4jEventConverter()));
+        juliLog.setFilter(new JuliBridgeFilter(juliLog.getFilter(), log, new JuliLog4jEventConverter()));
         String expectedMessage = "foo";
         
         juliLog.warning(expectedMessage);



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