Grails

Show sanitized stacktraces when errors occur (error.gsp)

Details

  • Type: New Feature New Feature
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 0.4
  • Fix Version/s: 1.2-M3
  • Component/s: None
  • Labels:
    None

Description

Something like this should be done:

def newTrace = []
traceText.tokenize('\n').each() { if (it.contains('.groovy:')) newTrace << it }

We could make more smarts there, use regex to pick out groovy source files and artifacts (which may not end in .groovy I noticed) and show either a list without any non-project files in, i.e. even exclude scripts/*.groovy etc... or show the full groovy only trace.

We could then, in dev mode, hyperlink to views to the source code files highlighting the error lines.

Activity

Hide
Marc Palmer added a comment -

This has been implemented by modifying the StackTrace elements in the exceptions themselves. This is because there is no other way to stop normal logging dumping out the full trace.

Show
Marc Palmer added a comment - This has been implemented by modifying the StackTrace elements in the exceptions themselves. This is because there is no other way to stop normal logging dumping out the full trace.
Hide
David Smiley added a comment -

FYI, ever since I started working with grails, I knew I had to get around this nasty grails problem, so I solved this for my project. What I did was find a log4j filter out there that would do this. I did on sf.net but I then found I had to extend it slightly to permit configuration via the properties form of log4j configuration because unfortunately grails works that way ( I wish it didn't; it's less flexible ). So in my Config.groovy I have this:

appender.stdout = "org.apache.log4j.ConsoleAppender"
   appender.'stdout.layout'="org.mitre.myproject.FilteredPatternLayout"
   appender.'stdout.layout.ConversionPattern'='[%r] %p %c{2} %m%n'
  appender.'stdout.layout.filters'='sun.reflect,org.codehaus.groovy.runtime,groovy.lang,java.lang.reflect.Method.invoke'

And I put openutils-log4j-1.0.1.jar into the lib directory, then I implemented FilteredPatternLayout like so:

/**
 * Extends same name in superclass and adds a feature to specify the filtered packages in a comma-separated manner.
 * The only real reason for this is to allow it to be used in a .properties style log4j configuration.  Grails
 * prefers log4j in the .properties format as of 0.5.6 and so this was deamed easier to do than to try to get grails
 * to use log4j's xml configuration.
 */
public class FilteredPatternLayout extends it.openutils.log4j.FilteredPatternLayout {

    /**
     * Comma separated list of values to supply to {@link #setFilter}
     * @param commaSeparatedFilters
     */
    public void setFilters(String commaSeparatedFilters) {
        String[] filters = commaSeparatedFilters.split(",");
        for (String filter : filters) {
            setFilter(filter);
        }
    }
    
}
Show
David Smiley added a comment - FYI, ever since I started working with grails, I knew I had to get around this nasty grails problem, so I solved this for my project. What I did was find a log4j filter out there that would do this. I did on sf.net but I then found I had to extend it slightly to permit configuration via the properties form of log4j configuration because unfortunately grails works that way ( I wish it didn't; it's less flexible ). So in my Config.groovy I have this:
appender.stdout = "org.apache.log4j.ConsoleAppender"
   appender.'stdout.layout'="org.mitre.myproject.FilteredPatternLayout"
   appender.'stdout.layout.ConversionPattern'='[%r] %p %c{2} %m%n'
  appender.'stdout.layout.filters'='sun.reflect,org.codehaus.groovy.runtime,groovy.lang,java.lang.reflect.Method.invoke'
And I put openutils-log4j-1.0.1.jar into the lib directory, then I implemented FilteredPatternLayout like so:
/**
 * Extends same name in superclass and adds a feature to specify the filtered packages in a comma-separated manner.
 * The only real reason for this is to allow it to be used in a .properties style log4j configuration.  Grails
 * prefers log4j in the .properties format as of 0.5.6 and so this was deamed easier to do than to try to get grails
 * to use log4j's xml configuration.
 */
public class FilteredPatternLayout extends it.openutils.log4j.FilteredPatternLayout {

    /**
     * Comma separated list of values to supply to {@link #setFilter}
     * @param commaSeparatedFilters
     */
    public void setFilters(String commaSeparatedFilters) {
        String[] filters = commaSeparatedFilters.split(",");
        for (String filter : filters) {
            setFilter(filter);
        }
    }
    
}
Hide
Marc Palmer added a comment -

Hi David - we've implemented this a different way already in 1.0 head.

Show
Marc Palmer added a comment - Hi David - we've implemented this a different way already in 1.0 head.
Hide
Graeme Rocher added a comment -

Moving non-critical issues that aren't going to make it into 1.1 to 1.2

Show
Graeme Rocher added a comment - Moving non-critical issues that aren't going to make it into 1.1 to 1.2
Hide
Graeme Rocher added a comment -

already done

Show
Graeme Rocher added a comment - already done

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: