You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2008/08/28 09:47:42 UTC
svn commit: r689749 -
/cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/InvocationImpl.java
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) {
Re: svn commit: r689749 - /cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/InvocationImpl.java
Posted by Joerg Heinicke <jo...@gmx.de>.
On 29.08.2008 07:45, Reinhard Pötz wrote:
>>> 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.
>> Shouldn't these kind of things be left to the logging implementation and
>> configuration?
>
> If I knew how to do this ... Log4j isn't really well documented.
I don't know either. I just "felt" wrong. Somebody else might know how
to do it or implement his own formatter.
I saw you already removed it. Thanks :)
Joerg
Re: svn commit: r689749 - /cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/InvocationImpl.java
Posted by Reinhard Pötz <re...@apache.org>.
Joerg Heinicke wrote:
> On 28.08.2008 09:47, reinhard@apache.org wrote:
>
>> 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.
>
> Shouldn't these kind of things be left to the logging implementation and
> configuration?
If I knew how to do this ... Log4j isn't really well documented.
Any hints?
--
Reinhard Pötz Managing Director, {Indoqa} GmbH
http://www.indoqa.com/en/people/reinhard.poetz/
Member of the Apache Software Foundation
Apache Cocoon Committer, PMC member reinhard@apache.org
________________________________________________________________________
Re: svn commit: r689749 - /cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/InvocationImpl.java
Posted by Joerg Heinicke <jo...@gmx.de>.
On 28.08.2008 09:47, reinhard@apache.org wrote:
> 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.
Shouldn't these kind of things be left to the logging implementation and
configuration?
Joerg