slhck
slhck

Reputation: 38672

How to debug parameters sent in Grails

Grails is so nice to append the parameters sent to console output in the case of an error:

2011-05-23 12:17:05,173 [http-8080-5] ERROR errors.GrailsExceptionResolver  - Exception occurred when processing request: [POST] / - parameters:
maps: on
maps: on
maps: on
maps: 
_isPublic: 
description: test
name: set1
isPublic: on
Stacktrace follows:
...

But how can I tell it to always show me which parameters are sent (like in Rails, for example)?

My current log4j configuration looks as follows:

error  'org.codehaus.groovy.grails.web.servlet',  //  controllers
       'org.codehaus.groovy.grails.web.pages', //  GSP
       'org.codehaus.groovy.grails.web.sitemesh', //  layouts
       'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
       'org.codehaus.groovy.grails.web.mapping', // URL mapping
       'org.codehaus.groovy.grails.commons', // core / classloading
       'org.codehaus.groovy.grails.plugins', // plugins
       'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
       'org.springframework',
       'org.hibernate',
       'net.sf.ehcache.hibernate'

warn   'org.mortbay.log'

Upvotes: 1

Views: 3060

Answers (2)

Dónal
Dónal

Reputation: 187529

I don't believe Grails itself supports logging the request parameters for each request. However, you can easily implement this yourself in a filter:

package com.example

class MyFilters {

  private static final log = org.apache.commons.logging.LogFactory.getLog(this)

  def filters = {
    paramLogger(controller:'*', action:'*') {
      before = {
        log.debug "request params: $params"
      }
    }
  }
} 

Remember to enable debug logging for this filter in `Config.groovy by adding

debug com.example

to the log4j closure

Upvotes: 2

mfloryan
mfloryan

Reputation: 7685

You probably want to get more output from org.codehaus.groovy.grails.web so set that one to a lower level (debug or trace)

Upvotes: 1

Related Questions