You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2008/08/25 11:15:19 UTC

svn commit: r688673 - /incubator/sling/trunk/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java

Author: fmeschbe
Date: Mon Aug 25 02:15:18 2008
New Revision: 688673

URL: http://svn.apache.org/viewvc?rev=688673&view=rev
Log:
SLING-613 log script errors in the request progress tracker

Modified:
    incubator/sling/trunk/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java

Modified: incubator/sling/trunk/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java?rev=688673&r1=688672&r2=688673&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java (original)
+++ incubator/sling/trunk/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java Mon Aug 25 02:15:18 2008
@@ -57,6 +57,7 @@
 import org.apache.sling.api.SlingException;
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.request.RequestProgressTracker;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceMetadata;
 import org.apache.sling.api.scripting.ScriptEvaluationException;
@@ -218,8 +219,17 @@
             eval(props);
 
         } catch (ScriptEvaluationException see) {
+
+            // log in the request progress tracker
+            logScriptError(request, see);
+            
             throw see;
+            
         } catch (Exception e) {
+            
+            // log in the request progress tracker
+            logScriptError(request, e);
+            
             throw new SlingException("Cannot get DefaultSlingScript: "
                 + e.getMessage(), e);
         }
@@ -451,8 +461,24 @@
 
     private String getLoggerName() {
         String name = getScriptResource().getPath();
-        name = name.replace('.', '$');
-        name = name.replace('/', '.');
+        name = name.substring(1);       // cut-off leading slash
+        name = name.replace('.', '$');  // extension separator as part of name
+        name = name.replace('/', '.');  // hierarchy defined by dot
         return name;
     }
+
+    /**
+     * Logs the error caused by executing the script in the request progress
+     * tracker.
+     */
+    private void logScriptError(SlingHttpServletRequest request,
+            Throwable throwable) {
+        String message = throwable.getMessage();
+        if (message != null) {
+            message = throwable.getMessage().replace('\n', '/');
+        } else {
+            message = throwable.toString();
+        }
+        request.getRequestProgressTracker().log("SCRIPT ERROR: {0}", message);
+    }
 }
\ No newline at end of file