jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chet...@apache.org
Subject svn commit: r1521747 - in /jackrabbit/oak/trunk/oak-jcr/src: main/java/org/apache/jackrabbit/oak/jcr/delegate/ main/java/org/apache/jackrabbit/oak/jcr/session/ main/java/org/apache/jackrabbit/oak/jcr/session/operation/ test/resources/
Date Wed, 11 Sep 2013 06:39:28 GMT
Author: chetanm
Date: Wed Sep 11 06:39:27 2013
New Revision: 1521747

URL: http://svn.apache.org/r1521747
Log:
OAK-946 - Improve support for debugging Oak

Adding logging about high level JCR operation being performed. Logs can be enabled
by turning on DEBUG logs for 'org.apache.jackrabbit.oak.jcr.operations'

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/PropertyImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/operation/SessionOperation.java
    jackrabbit/oak/trunk/oak-jcr/src/test/resources/logback-test.xml

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java?rev=1521747&r1=1521746&r2=1521747&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
Wed Sep 11 06:39:27 2013
@@ -57,12 +57,15 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.slf4j.Marker;
+import org.slf4j.MarkerFactory;
 
 /**
  * TODO document
  */
 public class SessionDelegate {
     static final Logger log = LoggerFactory.getLogger(SessionDelegate.class);
+    static final Logger operationLogger = LoggerFactory.getLogger("org.apache.jackrabbit.oak.jcr.operations");
 
     private final ContentSession contentSession;
     private final RefreshStrategy refreshStrategy;
@@ -128,7 +131,9 @@ public class SessionDelegate {
         }
         try {
             sessionOpCount++;
-            return sessionOperation.perform();
+            T result =  sessionOperation.perform();
+            logOperationDetails(sessionOperation);
+            return result;
         } finally {
             sessionOpCount--;
             if (sessionOperation.isUpdate()) {
@@ -424,6 +429,17 @@ public class SessionDelegate {
 
     //------------------------------------------------------------< internal >---
 
+    private <T> void logOperationDetails(SessionOperation<T> ops)  throws RepositoryException
{
+        if(operationLogger.isDebugEnabled()){
+            String desc = ops.description();
+            if(desc != null){
+                Marker sessionMarker = MarkerFactory.getMarker(this.toString());
+                operationLogger.debug(sessionMarker,desc);
+            }
+        }
+    }
+
+
     /**
      * Wraps the given {@link CommitFailedException} instance using the
      * appropriate {@link RepositoryException} subclass based on the

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java?rev=1521747&r1=1521746&r2=1521747&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java
Wed Sep 11 06:39:27 2013
@@ -212,6 +212,11 @@ public class NodeImpl<T extends NodeDele
                 dlg.remove();
                 return null;
             }
+
+            @Override
+            public String description() throws RepositoryException {
+                return String.format("Removing node [%s]",dlg.getPath());
+            }
         });
     }
 
@@ -244,6 +249,8 @@ public class NodeImpl<T extends NodeDele
 
         SessionImpl.checkIndexOnName(sessionContext, relPath);
         return perform(new ItemWriteOperation<Node>() {
+            private NodeDelegate nodeAdded;
+
             @Override
             public Node perform() throws RepositoryException {
                 String oakName = PathUtils.getName(oakPath);
@@ -280,8 +287,15 @@ public class NodeImpl<T extends NodeDele
                 if (added == null) {
                     throw new ItemExistsException();
                 }
+                nodeAdded = added;
+
                 return NodeImpl.createNode(added, sessionContext);
             }
+
+            @Override
+            public String description() {
+                return String.format("Adding node [%s]",nodeAdded.getPath());
+            }
         });
     }
 
@@ -1291,7 +1305,7 @@ public class NodeImpl<T extends NodeDele
     }
 
     private Property internalSetProperty(
-            String jcrName, final Value value, final boolean exactTypeMatch)
+            final String jcrName, final Value value, final boolean exactTypeMatch)
             throws RepositoryException {
         final String oakName = getOakPathOrThrow(checkNotNull(jcrName));
         final PropertyState state = createSingleState(
@@ -1311,11 +1325,16 @@ public class NodeImpl<T extends NodeDele
                         dlg.setProperty(state, exactTypeMatch, false),
                         sessionContext);
             }
+
+            @Override
+            public String description() throws RepositoryException {
+                return String.format("Setting property [%s/%s]",dlg.getPath(),jcrName);
+            }
         });
     }
 
     private Property internalSetProperty(
-            String jcrName, final Value[] values,
+            final String jcrName, final Value[] values,
             final int type, final boolean exactTypeMatch)
             throws RepositoryException {
         final String oakName = getOakPathOrThrow(checkNotNull(jcrName));
@@ -1336,6 +1355,11 @@ public class NodeImpl<T extends NodeDele
                         dlg.setProperty(state, exactTypeMatch, false),
                         sessionContext);
             }
+
+            @Override
+            public String description() throws RepositoryException {
+                return String.format("Setting property [%s/%s]",dlg.getPath(),jcrName);
+            }
         });
     }
 
@@ -1371,6 +1395,11 @@ public class NodeImpl<T extends NodeDele
                 }
                 return new PropertyImpl(property, sessionContext);
             }
+
+            @Override
+            public String description() throws RepositoryException {
+                return String.format("Removing property [%s]",jcrName);
+            }
         });
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/PropertyImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/PropertyImpl.java?rev=1521747&r1=1521746&r2=1521747&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/PropertyImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/PropertyImpl.java
Wed Sep 11 06:39:27 2013
@@ -108,6 +108,11 @@ public class PropertyImpl extends ItemIm
                 dlg.remove();
                 return null;
             }
+
+            @Override
+            public String description() throws RepositoryException {
+                return String.format("Removing property [%s/%s] ",dlg.getPath(),dlg.getName());
+            }
         });
     }
 
@@ -446,6 +451,11 @@ public class PropertyImpl extends ItemIm
                 dlg.setState(createSingleState(dlg.getName(), converted, type));
                 return null;
             }
+
+            @Override
+            public String description() throws RepositoryException {
+                return String.format("Setting property [%s/%s]",dlg.getPath(),dlg.getName());
+            }
         });
     }
 
@@ -471,6 +481,11 @@ public class PropertyImpl extends ItemIm
                 dlg.setState(createMultiState(dlg.getName(), converted, type));
                 return null;
             }
+
+            @Override
+            public String description() throws RepositoryException {
+                return String.format("Setting property [%s/%s]",dlg.getPath(),dlg.getName());
+            }
         });
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionImpl.java?rev=1521747&r1=1521746&r2=1521747&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionImpl.java
Wed Sep 11 06:39:27 2013
@@ -399,6 +399,11 @@ public class SessionImpl implements Jack
             public boolean isSave() {
                 return true;
             }
+
+            @Override
+            public String description() {
+                return "Session saved";
+            }
         });
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/operation/SessionOperation.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/operation/SessionOperation.java?rev=1521747&r1=1521746&r2=1521747&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/operation/SessionOperation.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/operation/SessionOperation.java
Wed Sep 11 06:39:27 2013
@@ -61,4 +61,14 @@ public abstract class SessionOperation<T
 
     public abstract T perform() throws RepositoryException;
 
+    /**
+     * Provide details about the operation being performed
+     *
+     * @return operation description. Would return <code>null</code>
+     * if no description provided
+     */
+    public String description() throws RepositoryException{
+        return null;
+    }
+
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/resources/logback-test.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/resources/logback-test.xml?rev=1521747&r1=1521746&r2=1521747&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/resources/logback-test.xml (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/resources/logback-test.xml Wed Sep 11 06:39:27 2013
@@ -25,12 +25,13 @@
     <appender name="file" class="ch.qos.logback.core.FileAppender">
         <file>target/unit-tests.log</file>
         <encoder>
-            <pattern>%date{HH:mm:ss.SSS} %-5level %-40([%thread] %F:%L) %msg%n</pattern>
+            <pattern>%date{HH:mm:ss.SSS} %-5level %-40([%thread] %F:%L) %marker %msg%n</pattern>
         </encoder>
     </appender>
 
     <logger name="org.apache.jackrabbit.test.api" level="DEBUG"/>
     <logger name="com.mongodb.tcp" level="ERROR"/>
+    <logger name="org.apache.jackrabbit.oak.jcr.operations" level="INFO"/>
 
     <root level="INFO">
         <!--



Mime
View raw message