logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1382240 - in /logging/log4j/log4j2/trunk: api/src/main/java/org/apache/logging/log4j/ core/src/main/java/org/apache/logging/log4j/core/filter/ slf4j-impl/src/main/java/org/slf4j/helpers/ slf4j-impl/src/test/java/org/apache/logging/slf4j/ s...
Date Sat, 08 Sep 2012 06:27:00 GMT
Author: rgoers
Date: Sat Sep  8 06:27:00 2012
New Revision: 1382240

URL: http://svn.apache.org/viewvc?rev=1382240&view=rev
Log:
Fix LOG4J2-82 - MarkerFilter caused Markers to be created potentially incorrects. MarkerWrapper
now operates on the name, not the Marker.

Added:
    logging/log4j/log4j2/trunk/slf4j-impl/src/test/java/org/apache/logging/slf4j/MarkerTest.java
Modified:
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Marker.java
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/MarkerManager.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/MarkerFilter.java
    logging/log4j/log4j2/trunk/slf4j-impl/src/main/java/org/slf4j/helpers/MarkerWrapper.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Marker.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Marker.java?rev=1382240&r1=1382239&r2=1382240&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Marker.java (original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Marker.java Sat
Sep  8 06:27:00 2012
@@ -45,4 +45,11 @@ public interface Marker extends Serializ
      * @return true of this Marker or one of its ancestors is the specified Marker, false
otherwise.
      */
     boolean isInstanceOf(Marker m);
+
+    /**
+     * Checks whether this Marker is an instance of the specified Marker.
+     * @param m The Marker name to check.
+     * @return true of this Marker or one of its ancestors matches the specified name, false
otherwise.
+     */
+    boolean isInstanceOf(String name);
 }

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/MarkerManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/MarkerManager.java?rev=1382240&r1=1382239&r2=1382240&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/MarkerManager.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/MarkerManager.java
Sat Sep  8 06:27:00 2012
@@ -109,12 +109,26 @@ public final class MarkerManager {
             return false;
         }
 
+        public boolean isInstanceOf(String name) {
+            if (name == null) {
+                throw new IllegalArgumentException("A marker name is required");
+            }
+            Marker toTest = this;
+            do {
+                if (name.equals(toTest.getName())) {
+                    return true;
+                }
+                toTest = toTest.getParent();
+            } while (toTest != null);
+            return false;
+        }
+
         @Override
         public boolean equals(Object o) {
             if (this == o) {
                 return true;
             }
-            if (o == null || getClass() != o.getClass()) {
+            if (o == null || !(o instanceof Marker)) {
                 return false;
             }
 

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/MarkerFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/MarkerFilter.java?rev=1382240&r1=1382239&r2=1382240&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/MarkerFilter.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/MarkerFilter.java
Sat Sep  8 06:27:00 2012
@@ -34,11 +34,11 @@ import org.apache.logging.log4j.message.
 @Plugin(name = "MarkerFilter", type = "Core", elementType = "filter", printObject = true)
 public final class MarkerFilter extends FilterBase {
 
-    private final Marker marker;
+    private final String name;
 
-    private MarkerFilter(Marker marker, Result onMatch, Result onMismatch) {
+    private MarkerFilter(String name, Result onMatch, Result onMismatch) {
         super(onMatch, onMismatch);
-        this.marker = marker;
+        this.name = name;
     }
 
     public Result filter(Logger logger, Level level, Marker marker, String msg, Object[]
params) {
@@ -59,17 +59,17 @@ public final class MarkerFilter extends 
     }
 
     private Result filter(Marker marker) {
-        return marker != null && marker.isInstanceOf(this.marker) ? onMatch : onMismatch;
+        return marker != null && marker.isInstanceOf(name) ? onMatch : onMismatch;
     }
 
     @Override
     public String toString() {
-        return marker.getName();
+        return name;
     }
 
     /**
      * Create the MarkerFilter.
-     * @param marker The Marker to match.
+     * @param marker The Marker name to match.
      * @param match The action to take if a match occurs.
      * @param mismatch The action to take if no match occurs.
      * @return A MarkerFilter.
@@ -83,11 +83,10 @@ public final class MarkerFilter extends 
             LOGGER.error("A marker must be provided for MarkerFilter");
             return null;
         }
-        Marker m = MarkerManager.getMarker(marker);
         Result onMatch = match == null ? null : Result.valueOf(match.toUpperCase());
         Result onMismatch = mismatch == null ? null : Result.valueOf(mismatch.toUpperCase());
 
-        return new MarkerFilter(m, onMatch, onMismatch);
+        return new MarkerFilter(marker, onMatch, onMismatch);
     }
 
 }

Modified: logging/log4j/log4j2/trunk/slf4j-impl/src/main/java/org/slf4j/helpers/MarkerWrapper.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/slf4j-impl/src/main/java/org/slf4j/helpers/MarkerWrapper.java?rev=1382240&r1=1382239&r2=1382240&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/slf4j-impl/src/main/java/org/slf4j/helpers/MarkerWrapper.java
(original)
+++ logging/log4j/log4j2/trunk/slf4j-impl/src/main/java/org/slf4j/helpers/MarkerWrapper.java
Sat Sep  8 06:27:00 2012
@@ -49,6 +49,17 @@ public class MarkerWrapper extends Basic
             throw new IllegalArgumentException("A marker parameter is required");
         }
 
-        return contains((MarkerWrapper) marker);
+        if (marker instanceof MarkerWrapper) {
+            return contains((MarkerWrapper) marker);
+        } else {
+            return contains(marker.getName());
+        }
+    }
+
+    public boolean isInstanceOf(String name) {
+        if (name == null) {
+            throw new IllegalArgumentException("A marker name is required");
+        }
+        return contains(name);
     }
 }

Added: logging/log4j/log4j2/trunk/slf4j-impl/src/test/java/org/apache/logging/slf4j/MarkerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/slf4j-impl/src/test/java/org/apache/logging/slf4j/MarkerTest.java?rev=1382240&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/slf4j-impl/src/test/java/org/apache/logging/slf4j/MarkerTest.java
(added)
+++ logging/log4j/log4j2/trunk/slf4j-impl/src/test/java/org/apache/logging/slf4j/MarkerTest.java
Sat Sep  8 06:27:00 2012
@@ -0,0 +1,43 @@
+/*
+ * 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.slf4j;
+
+import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.MarkerManager;
+import org.junit.Test;
+import org.slf4j.helpers.MarkerWrapper;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ *
+ */
+public class MarkerTest {
+
+    @Test
+    public void testMarker() {
+        org.slf4j.Marker slf4jMarker = org.slf4j.MarkerFactory.getMarker("TEST");
+        org.slf4j.Marker slf4jParent = org.slf4j.MarkerFactory.getMarker("PARENT");
+        slf4jMarker.add(slf4jParent);
+        Marker log4jParent = MarkerManager.getMarker("PARENT");
+        Marker log4jMarker = MarkerManager.getMarker("TEST", log4jParent);
+
+        assertTrue("Incorrect Marker class", slf4jMarker instanceof MarkerWrapper);
+        assertTrue("SLF4J Marker doesn't match Log4j Marker", ((MarkerWrapper) slf4jMarker).isInstanceOf(log4jMarker));
+        assertTrue("SLF4J Parent doesn't match Log4j parent", ((MarkerWrapper) slf4jMarker).isInstanceOf(log4jParent));
+    }
+}

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1382240&r1=1382239&r2=1382240&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Sat Sep  8 06:27:00 2012
@@ -23,6 +23,11 @@
 
   <body>
     <release version="2.0-alpha3" date="TBD" description="">
+      <action issue="LOG4J2-82" dev="rgoers" type="fix">
+        MarkerFilter called MarkerManager.getMarker causing the Marker to be created during
the processing of the
+        configuration. This prevents the application from creating the Marker with any parents.
MarkerWrapper in
+        SLF4J-impl was getting a ClassCastException in instanceOf because the Marker isn't
a MarkerWrapper.
+      </action>
       <action issue="LOG4J2-80" dev="rgoers" type="fix" due-to="Oliver Lamy">
         Allow Log4j 2 to be used as the implementation with SLF4J and SLF4J's jcl-over-slf4j
by adding filtering
         to the log method in SLF4JLogger.



Mime
View raw message