1

I thought by doing:

appenders {
     ...
     'null' name: 'stacktrace'
     ...
}

I would see no exceptions in my log. I still see exceptions being logged in GrailsExceptionResolver in my log.

 ERROR errors.GrailsExceptionResolver - Exception occurred when processing request: [GET] /api//products - parameters:

But for some exceptions, I don't want to log a stacktrace. These are kind of benign things but because of legacy code, I can't just remove them as exceptions as they use in deep call stacks.

So I just need to control the way Grails is logging every exception.

Any tips?

More Than Five
  • 9,959
  • 21
  • 77
  • 127
  • http://stackoverflow.com/questions/4972954/how-to-disable-loggers-of-a-class-or-of-whole-package – V H Jan 13 '15 at 11:50

1 Answers1

1

You could add log4j Filter GrailsExceptionResolver.

public class ExceptionLoggerFilter extends Filter {

    String loggerClass;

    @Override
    public int decide(LoggingEvent event) {

        if (event.getLoggerName().equals(loggerClass)) {

            if (event.getThrowableInformation() != null) {
                return Filter.DENY;
            }
        }
        return Filter.NEUTRAL;
    }

    public String getLoggerClass() {
        return loggerClass;
    }

    public void setLoggerClass(String loggerClass) {
        this.loggerClass = loggerClass;
    }

}

and register this filter in BootStrap.groovy

 def init = { servletContext ->

        Logger.rootLogger.allAppenders.each { appender ->
            ExceptionLoggerFilter filter = new ExceptionLoggerFilter()
            filter.loggerClass = "org.codehaus.groovy.grails.web.errors.GrailsExceptionResolver"
            filter.activateOptions()
            appender.addFilter(filter)
        }
    }
Constantine Gladky
  • 1,245
  • 6
  • 27
  • 45