cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r689749 - /cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/InvocationImpl.java
Date Thu, 28 Aug 2008 07:47:42 GMT
Author: reinhard
Date: Thu Aug 28 00:47:42 2008
New Revision: 689749

URL: http://svn.apache.org/viewvc?rev=689749&view=rev
Log:
improve error reporting: print the full stacktrace when the loglevel is set to INFO or below.
Otherwise only print the first 5 lines.

Modified:
    cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/InvocationImpl.java

Modified: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/InvocationImpl.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/InvocationImpl.java?rev=689749&r1=689748&r2=689749&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/InvocationImpl.java
(original)
+++ cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/InvocationImpl.java
Thu Aug 28 00:47:42 2008
@@ -35,17 +35,25 @@
 import org.apache.cocoon.corona.sitemap.expression.LanguageInterpreter;
 import org.apache.cocoon.corona.sitemap.objectmodel.ObjectModel;
 import org.apache.cocoon.corona.sitemap.util.ParameterHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 public class InvocationImpl implements Invocation {
 
+    private final Log logger = LogFactory.getLog(this.getClass());
+
     private static final Pattern PARAMETER_PATTERN = Pattern.compile("\\{([a-zA-Z\\-]+):([^\\{]*)\\}");
 
-    private final List<Action> actions = new LinkedList<Action>();
+    private List<Action> actions = new LinkedList<Action>();
 
     private ComponentProvider componentProvider;
+
     private OutputStream outputStream;
+
     private Map<String, Object> parameters = new HashMap<String, Object>();
+
     private Pipeline pipeline;
+
     private String requestURI;
 
     private URL baseURL;
@@ -307,6 +315,40 @@
 
         this.objectModel.getCoronaObject().put("exception", throwable);
         ParameterHelper.setThrowable(this.parameters, throwable);
+        this.logThrowable(throwable);
+    }
+
+    private void logThrowable(Throwable throwable) {
+        String message = "Error while executing the sitemap. [request-uri=" + this.getRequestURI()
+ "]";
+        if (this.logger.isInfoEnabled()) {
+            this.logger.error(message, throwable);
+        } else {
+            StringBuilder errorSb = new StringBuilder();
+            errorSb.append(message).append("\n");
+            errorSb.append(throwable.getClass().getName()).append(": ");
+            errorSb.append(throwable.getMessage()).append("\n");
+
+            StackTraceElement[] stackTrace = throwable.getStackTrace();
+            int counter = 0;
+            for (StackTraceElement stackTraceElement : stackTrace) {
+                errorSb.append("  ");
+
+                if (counter == 5) {
+                    errorSb.append("... ").append(stackTrace.length - counter);
+                    errorSb.append(" more stacktrace elements are available. ");
+                    errorSb.append("Loglevel INFO or lower prints them all.");
+                    break;
+                }
+
+                errorSb.append(stackTraceElement.getClassName()).append(".").append(stackTraceElement.getMethodName());
+                errorSb.append("(").append(stackTraceElement.getFileName()).append(":");
+                errorSb.append(stackTraceElement.getLineNumber()).append(")\n");
+
+                counter++;
+            }
+
+            this.logger.error(errorSb.toString());
+        }
     }
 
     private LanguageInterpreter getLanguageInterpreter(final String language) {



Mime
View raw message