4

In grails I want to stop logging some specific exceptions occouring in my controllers.

I have managed this exception with urlmapping to render a custome warning page

Es my url mapping

"500"(controller:'error', action:'excOne', exception: MyExceptionOne)       
"500"(controller:'error', action:'excTwo', exception: MyExceptionTwo)

But this exceptions continued to be logged by log4j. How I can exclude them from logging?

This is my log4j config:

log4j = {
      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.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',
        'grails.app.services.org.grails.plugin.resource',
        'grails.app.taglib.org.grails.plugin.resource',
        'grails.app.resourceMappers.org.grails.plugin.resource',
        'grails.app.services.NavigationService'


    warn   'org.mortbay.log'    
    debug  "com.myproject.*"

    debug  "grails.app"
    debug  "com.myproject.*"

appenders {
console name:'stdout', layout:pattern(conversionPattern: '[%r] %c{2} %m%n')
}

root {
error 'stdout'
warn 'stdout'
additivity = true
} 

}
tim_yates
  • 167,322
  • 27
  • 342
  • 338
Fabiano Taioli
  • 5,270
  • 1
  • 35
  • 49

2 Answers2

0

I have not managed to remove all mentions of the exception in the log, but what I have done is I prevented the stack trace from cluttering up the logs:

Create a StackTracePrinter implementation that behaves the way you want.

package com.myStuff
import org.codehaus.groovy.grails.exceptions.DefaultStackTracePrinter

class MyStackTracePrinter extends DefaultStackTracePrinter {

  String prettyPrint(Throwable throwable) {
    if (throwable instanceof MyException) return "<stack trace suppressed>"
    return super.prettyPrint(throwable)
  }
}

Then, in Config.groovy:

grails.logging.stackTracePrinterClass = 'com.myStuff.MyStackTracePrinter'
Nancy Deschênes
  • 355
  • 1
  • 11
-1

Try:

off "your.class.file"

After the line of code:

debug  "com.myproject.*"

Just make sure you provide correct path of your class, let me know the class file path if this doesn't work?

mehmood
  • 301
  • 3
  • 19