logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1586864 - in /logging/log4j/log4j2/trunk: log4j-api/src/main/java/org/apache/logging/log4j/ log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/ src/site/xdoc/manual/
Date Sat, 12 Apr 2014 15:51:00 GMT
Author: rgoers
Date: Sat Apr 12 15:51:00 2014
New Revision: 1586864

URL: http://svn.apache.org/r1586864
Log:
LOG4J2-585 - More Marker changes

Modified:
    logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/Marker.java
    logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/MarkerManager.java
    logging/log4j/log4j2/trunk/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jMarker.java
    logging/log4j/log4j2/trunk/src/site/xdoc/manual/markers.xml

Modified: logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/Marker.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/Marker.java?rev=1586864&r1=1586863&r2=1586864&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/Marker.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/Marker.java
Sat Apr 12 15:51:00 2014
@@ -41,12 +41,18 @@ public interface Marker extends Serializ
     Marker getParent();
 
     /**
-     * Returns the list of parents of this Marker.
+     * Returns a list of parents of this Marker.
      * @return The parent Markers or null if this Marker has no parents.
      */
     Marker[] getParents();
 
     /**
+     * Indicates whether this Marker has references to any other Markers.
+     * @return true if the Marker has parent Markers.
+     */
+    boolean hasParents();
+
+    /**
      * Checks whether this Marker is an instance of the specified Marker.
      * @param m The Marker to check.
      * @return true of this Marker or one of its ancestors is the specified Marker, false
otherwise.
@@ -63,8 +69,16 @@ public interface Marker extends Serializ
     /**
      * Adds a Marker as a parent to this Marker.
      * @param marker The parent marker to add.
+     * @return The current Marker object, thus allowing multiple adds to be concatenated.
+     */
+    Marker add(Marker marker);
+
+    /**
+     * Replaces the set of parent Markers with the provided Markers.
+     * @param markers The new set of parent Markers or null.
+     * @return The current Marker object.
      */
-    void add(Marker marker);
+    Marker set(Marker... markers);
 
     /**
      * Removes the specified Marker as a parent of this Marker.

Modified: logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/MarkerManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/MarkerManager.java?rev=1586864&r1=1586863&r2=1586864&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/MarkerManager.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/MarkerManager.java
Sat Apr 12 15:51:00 2014
@@ -49,6 +49,7 @@ public final class MarkerManager {
      * @param parent The name of the parent Marker.
      * @return The Marker with the specified name.
      * @throws IllegalArgumentException if the parent Marker does not exist.
+     * @deprecated Use the Marker add or set methods to add parent Markers. Will be removed
by final GA release.
      */
     public static Marker getMarker(final String name, final String parent) {
         final Marker parentMarker = markerMap.get(parent);
@@ -63,23 +64,12 @@ public final class MarkerManager {
      * @param name The name of the Marker.
      * @param parent The parent Marker.
      * @return The Marker with the specified name.
+     * @deprecated Use the Marker add or set methods to add parent Markers. Will be removed
by final GA release.
      */
     public static Marker getMarker(final String name, final Marker parent) {
-        markerMap.putIfAbsent(name, new Log4jMarker(name, parent));
-        return markerMap.get(name);
+        markerMap.putIfAbsent(name, new Log4jMarker(name));
+        return markerMap.get(name).add(parent);
     }
-
-    /**
-     * Retrieves or creates a Marker with the specified parents.
-     * @param name The name of the Marker.
-     * @param parents The parent Markers.
-     * @return The Marker with the specified name.
-     */
-    public static Marker getMarker(final String name, final Marker... parents) {
-        markerMap.putIfAbsent(name, new Log4jMarker(name, parents));
-        return markerMap.get(name);
-    }
-
     /**
      * The actual Marker implementation.
      */
@@ -95,29 +85,14 @@ public final class MarkerManager {
             this.parents = null;
         }
 
-        public Log4jMarker(final String name, final Marker parent) {
-            this.name = name;
-            this.parents = parent != null ? new Marker[] {parent} : null;
-        }
-
-        public Log4jMarker(final String name, final Marker... parents) {
-            this.name = name;
-            for (Marker marker : parents) {
-                if (marker == null) {
-                    throw new IllegalArgumentException("Marker cannot contain a null parent");
-                }
-            }
-            this.parents = parents;
-        }
-
         @Override
-        public synchronized void add(Marker parent) {
+        public synchronized Marker add(Marker parent) {
             if (parent == null) {
                 throw new IllegalArgumentException("A parent marker must be specified");
             }
             // Don't add a parent that is already in the hierarchy.
             if (parents != null && (this.isInstanceOf(parent) || parent.isInstanceOf(this)))
{
-                return;
+                return this;
             }
             int size = parents == null ? 1 : parents.length + 1;
             Marker[] markers = new Marker[size];
@@ -126,6 +101,7 @@ public final class MarkerManager {
             }
             markers[size - 1] = parent;
             parents = markers;
+            return this;
         }
 
         @Override
@@ -159,6 +135,18 @@ public final class MarkerManager {
         }
 
         @Override
+        public Marker set(Marker... markers) {
+            if (markers == null || markers.length == 0) {
+                this.parents = null;
+            } else {
+                Marker[] array = new Marker[markers.length];
+                System.arraycopy(markers, 0, array, 0, markers.length);
+                this.parents = array;
+            }
+            return this;
+        }
+
+        @Override
         public String getName() {
             return this.name;
         }
@@ -170,7 +158,17 @@ public final class MarkerManager {
 
         @Override
         public Marker[] getParents() {
-            return this.parents;
+            if (this.parents == null) {
+                return null;
+            }
+            Marker[] markers = new Marker[this.parents.length];
+            System.arraycopy(this.parents, 0, markers, 0, this.parents.length);
+            return markers;
+        }
+
+        @Override
+        public boolean hasParents() {
+            return this.parents == null;
         }
 
         @Override
@@ -234,7 +232,7 @@ public final class MarkerManager {
             if (parent == marker) {
                 return true;
             }
-            Marker[] localParents = parent.getParents();
+            Marker[] localParents = parent instanceof Log4jMarker ? ((Log4jMarker)parent).parents
: parent.getParents();
             if (localParents != null) {
                 if (localParents.length == 1) {
                     return checkParent(localParents[0], marker);
@@ -293,7 +291,7 @@ public final class MarkerManager {
                 }
                 first = false;
                 sb.append(marker.getName());
-                Marker[] p = marker.getParents();
+                Marker[] p = marker instanceof Log4jMarker ? ((Log4jMarker)marker).parents
: marker.getParents();
                 if (p != null) {
                     addParentInfo(p, sb);
                 }

Modified: logging/log4j/log4j2/trunk/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jMarker.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jMarker.java?rev=1586864&r1=1586863&r2=1586864&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jMarker.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jMarker.java
Sat Apr 12 15:51:00 2014
@@ -22,7 +22,6 @@ import org.slf4j.Marker;
 import org.slf4j.impl.StaticMarkerBinder;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 
@@ -61,12 +60,12 @@ public class Log4jMarker implements Mark
 
     @Override
     public boolean hasReferences() {
-        return marker.getParents() != null;
+        return marker.hasParents();
     }
 
     @Override
     public boolean hasChildren() {
-        return marker.getParents() != null;
+        return marker.hasParents();
     }
 
     @Override

Modified: logging/log4j/log4j2/trunk/src/site/xdoc/manual/markers.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/site/xdoc/manual/markers.xml?rev=1586864&r1=1586863&r2=1586864&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/site/xdoc/manual/markers.xml (original)
+++ logging/log4j/log4j2/trunk/src/site/xdoc/manual/markers.xml Sat Apr 12 15:51:00 2014
@@ -43,8 +43,8 @@ public class MyApp {
 
     private Logger logger = LogManager.getLogger(MyApp.class.getName());
     private static final Marker SQL_MARKER = MarkerManager.getMarker("SQL");
-    private static final Marker UPDATE_MARKER = MarkerManager.getMarker("SQL_UPDATE", SQL_MARKER);
-    private static final Marker QUERY_MARKER = MarkerManager.getMarker("SQL_QUERY", SQL_MARKER);
+    private static final Marker UPDATE_MARKER = MarkerManager.getMarker("SQL_UPDATE").set(SQL_MARKER);
+    private static final Marker QUERY_MARKER = MarkerManager.getMarker("SQL_QUERY").set(SQL_MARKER);
 
     public String doQuery(String table) {
         logger.entry(param);
@@ -88,11 +88,12 @@ public class MyApp {
                   dependencies, unless that is what is desired.</li>
                 <li>Parent Markers can be added or removed dynamically. However, this
is fairly expensive to do.
                   Instead, it is recommended that the parents be identified when obtaining
the Marker the first time
-                  as shown in the examples above.</li>
+                  as shown in the examples above. Specifically, the set method replaces all
the markers in
+                  a single operation while add and remove act on only a single Marker at
a time.</li>
                 <li>Evaluating Markers with multiple ancestors is much more expensive
than Markers with no parents.
                   For example, in one set of tests to evaluate whether a Marker matched its
grandparent took 3
                   times longer than evaluating the Marker itself. Even then though, evaluating
Markers is
-                  inexpensive compared resolving the callers class name or line number.</li>
+                  inexpensive compared to resolving the callers class name or line number.</li>
               </ol>
             </p>
           </subsection>



Mime
View raw message