logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bbrou...@apache.org
Subject svn commit: r1601053 - in /logging/log4j/log4j2/trunk: log4j-api/src/main/java/org/apache/logging/log4j/ log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ log4j-nosql/ log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/ log...
Date Sat, 07 Jun 2014 01:47:53 GMT
Author: bbrouwer
Date: Sat Jun  7 01:47:53 2014
New Revision: 1601053

URL: http://svn.apache.org/r1601053
Log:
Remove the deprecated org.apache.logging.log4j.Marker.getParent()

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-core/src/main/java/org/apache/logging/log4j/core/jackson/MarkerMixIn.java
    logging/log4j/log4j2/trunk/log4j-nosql/   (props changed)
    logging/log4j/log4j2/trunk/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/NoSQLDatabaseManager.java
    logging/log4j/log4j2/trunk/log4j-nosql/src/test/java/org/apache/logging/log4j/nosql/appender/NoSQLDatabaseManagerTest.java
    logging/log4j/log4j2/trunk/log4j-to-slf4j/src/main/java/org/apache/logging/slf4j/SLF4JLogger.java

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=1601053&r1=1601052&r2=1601053&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 Jun  7 01:47:53 2014
@@ -34,14 +34,6 @@ public interface Marker extends Serializ
     String getName();
 
     /**
-     * Returns the first parent of this Marker.
-     * @return The first parent Marker or {@code null} if this Marker has no parents.
-     * @deprecated Use getParents() instead.
-     */
-    @Deprecated
-    Marker getParent();
-
-    /**
      * Returns a list of parents of this Marker.
      * @return The parent Markers or {@code null} if this Marker has no parents.
      */

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=1601053&r1=1601052&r2=1601053&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 Jun  7 01:47:53 2014
@@ -219,11 +219,6 @@ public final class MarkerManager {
         }
 
         @Override
-        public Marker getParent() {
-            return this.parents != null ? parents[0] : null;
-        }
-
-        @Override
         public Marker[] getParents() {
             if (this.parents == null) {
                 return null;

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/MarkerMixIn.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/MarkerMixIn.java?rev=1601053&r1=1601052&r2=1601053&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/MarkerMixIn.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/MarkerMixIn.java
Sat Jun  7 01:47:53 2014
@@ -67,10 +67,6 @@ abstract class MarkerMixIn implements Ma
     @JacksonXmlProperty(isAttribute = true)
     public abstract String getName();
 
-    @JsonIgnore
-    @Override
-    public abstract Marker getParent();
-
     @Override
     @JsonProperty(JsonConstants.ELT_PARENTS)
     @JacksonXmlElementWrapper(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_PARENTS)

Propchange: logging/log4j/log4j2/trunk/log4j-nosql/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Sat Jun  7 01:47:53 2014
@@ -3,3 +3,5 @@ target
 .classpath
 .project
 .settings
+
+bin

Modified: logging/log4j/log4j2/trunk/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/NoSQLDatabaseManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/NoSQLDatabaseManager.java?rev=1601053&r1=1601052&r2=1601053&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/NoSQLDatabaseManager.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/NoSQLDatabaseManager.java
Sat Jun  7 01:47:53 2014
@@ -87,17 +87,7 @@ public final class NoSQLDatabaseManager<
         if (marker == null) {
             entity.set("marker", (Object) null);
         } else {
-            final NoSQLObject<W> originalMarkerEntity = this.connection.createObject();
-            NoSQLObject<W> markerEntity = originalMarkerEntity;
-            markerEntity.set("name", marker.getName());
-            while (marker.getParent() != null) {
-                marker = marker.getParent();
-                final NoSQLObject<W> parentMarkerEntity = this.connection.createObject();
-                parentMarkerEntity.set("name", marker.getName());
-                markerEntity.set("parent", parentMarkerEntity);
-                markerEntity = parentMarkerEntity;
-            }
-            entity.set("marker", originalMarkerEntity);
+            entity.set("marker", buildMarkerEntity(marker));
         }
 
         entity.set("threadName", event.getThreadName());
@@ -148,6 +138,22 @@ public final class NoSQLDatabaseManager<
         this.connection.insertObject(entity);
     }
 
+    private NoSQLObject<W> buildMarkerEntity(Marker marker) {
+        final NoSQLObject<W> entity = this.connection.createObject();
+        entity.set("name", marker.getName());
+
+        final Marker[] parents = marker.getParents();
+        if (parents != null) {
+            @SuppressWarnings("unchecked")
+            final NoSQLObject<W>[] parentEntities = new NoSQLObject[parents.length];
+            for (int i = 0; i < parents.length; i++) {
+                parentEntities[i] = buildMarkerEntity(parents[i]);
+            }
+            entity.set("parents", parentEntities);
+        }
+        return entity;
+    }
+
     @Override
     protected void commitAndClose() {
         try {

Modified: logging/log4j/log4j2/trunk/log4j-nosql/src/test/java/org/apache/logging/log4j/nosql/appender/NoSQLDatabaseManagerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-nosql/src/test/java/org/apache/logging/log4j/nosql/appender/NoSQLDatabaseManagerTest.java?rev=1601053&r1=1601052&r2=1601053&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-nosql/src/test/java/org/apache/logging/log4j/nosql/appender/NoSQLDatabaseManagerTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-nosql/src/test/java/org/apache/logging/log4j/nosql/appender/NoSQLDatabaseManagerTest.java
Sat Jun  7 01:47:53 2014
@@ -467,8 +467,8 @@ public class NoSQLDatabaseManagerTest {
             expect(message.getFormattedMessage()).andReturn("Another cool message 02.");
             expect(event.getSource()).andReturn(new StackTraceElement("com.bar.Foo", "anotherMethod03",
"Foo.java", 9));
             expect(event.getMarker()).andReturn(
-                    MarkerManager.getMarker("AnotherMarker",
-                            MarkerManager.getMarker("Parent1", MarkerManager.getMarker("Grandparent2"))));
+                    MarkerManager.getMarker("AnotherMarker").addParents(MarkerManager.getMarker("Parent1").addParents(MarkerManager.getMarker("GrandParent1")),
+                            MarkerManager.getMarker("Parent2")));
             expect(event.getThreadName()).andReturn("AnotherThread-B");
             expect(event.getTimeMillis()).andReturn(987654321564L).times(2);
             expect(event.getThrown()).andReturn(exception2);
@@ -505,15 +505,33 @@ public class NoSQLDatabaseManagerTest {
             @SuppressWarnings("unchecked")
             final Map<String, Object> marker = (Map<String, Object>) object.get("marker");
             assertEquals("The marker name is not correct.", "AnotherMarker", marker.get("name"));
-            assertTrue("The marker parent should be a map.", marker.get("parent") instanceof
Map);
+
+            assertTrue("The marker parents should be a list.", marker.get("parents") instanceof
List);
             @SuppressWarnings("unchecked")
-            final Map<String, Object> parentMarker = (Map<String, Object>) marker.get("parent");
-            assertEquals("The marker parent name is not correct.", "Parent1", parentMarker.get("name"));
-            assertTrue("The marker grandparent should be a map.", parentMarker.get("parent")
instanceof Map);
-            @SuppressWarnings("unchecked")
-            final Map<String, Object> grandparentMarker = (Map<String, Object>)
parentMarker.get("parent");
-            assertEquals("The marker grandparent name is not correct.", "Grandparent2", grandparentMarker.get("name"));
-            assertNull("The grandparent marker should have no parent.", grandparentMarker.get("parent"));
+            final List<Object> markerParents = (List<Object>) marker.get("parents");
+            assertEquals("The marker parents should contain two parents", 2, markerParents.size());
+            
+            assertTrue("The marker parents[0] should be a map.", markerParents.get(0) instanceof
Map);
+            @SuppressWarnings("unchecked")
+            final Map<String, Object> parent1 = (Map<String, Object>) markerParents.get(0);
+            assertEquals("The first marker parent name is not correct.", "Parent1", parent1.get("name"));
+            
+            assertTrue("The marker parents[1] should be a map.", markerParents.get(1) instanceof
Map);
+            @SuppressWarnings("unchecked")
+            final Map<String, Object> parent2 = (Map<String, Object>) markerParents.get(1);
+            assertEquals("The second marker parent name is not correct.", "Parent2", parent2.get("name"));
+            assertNull("The second marker should have no parent.", parent2.get("parent"));
+
+            assertTrue("The parent1 parents should be a list.", parent1.get("parents") instanceof
List);
+            @SuppressWarnings("unchecked")
+            final List<Object> parent1Parents = (List<Object>) parent1.get("parents");
+            assertEquals("The parent1 parents should have only one parent", 1, parent1Parents.size());
+            
+            assertTrue("The parent1Parents[0] should be a map.", parent1Parents.get(0) instanceof
Map);
+            @SuppressWarnings("unchecked")
+            final Map<String, Object> parent1parent = (Map<String, Object>) parent1Parents.get(0);
+            assertEquals("The first parent1 parent name is not correct.", "GrandParent1",
parent1parent.get("name"));
+            assertNull("The parent1parent marker should have no parent.", parent1parent.get("parent"));
 
             assertTrue("The thrown should be a map.", object.get("thrown") instanceof Map);
             @SuppressWarnings("unchecked")

Modified: logging/log4j/log4j2/trunk/log4j-to-slf4j/src/main/java/org/apache/logging/slf4j/SLF4JLogger.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-to-slf4j/src/main/java/org/apache/logging/slf4j/SLF4JLogger.java?rev=1601053&r1=1601052&r2=1601053&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-to-slf4j/src/main/java/org/apache/logging/slf4j/SLF4JLogger.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-to-slf4j/src/main/java/org/apache/logging/slf4j/SLF4JLogger.java
Sat Jun  7 01:47:53 2014
@@ -93,11 +93,15 @@ public class SLF4JLogger extends Abstrac
         if (marker == null) {
             return null;
         }
-        final Marker parent = marker.getParent();
-        final org.slf4j.Marker parentMarker = parent == null ? null : getMarker(parent);
         final org.slf4j.Marker slf4jMarker = MarkerFactory.getMarker(marker.getName());
-        if (parentMarker != null && !slf4jMarker.contains(parentMarker)) {
-            slf4jMarker.add(parentMarker);
+        final Marker[] parents = marker.getParents();
+        if (parents != null) {
+            for (final Marker parent : parents) {
+                final org.slf4j.Marker slf4jParent = getMarker(parent);
+                if (!slf4jMarker.contains(slf4jParent)) {
+                    slf4jMarker.add(slf4jParent);
+                }
+            }
         }
         return slf4jMarker;
     }



Mime
View raw message