Thursday, September 11, 2008

Log4j configuration in Grails

Today when I config log4j for Grails I meet an exception,"No such property: context for class: java.lang.String" it's because of sometypo ,here is the wrong writing.
development {
log4j {
appender.access="org.apache.log4j.ConsoleAppender"
appender.'access.layout'="org.apache.log4j.PatternLayout"
appender.access.layout.ConversionPattern==%d %p %x [%c] %m%n //you must put the quote around "access.layout.ConversionPattern"
logger
{
grails.'app.controller.UserController'='warn,access'
}

}
}
following statement is copy from Grails official site,it explain why we should do it like that
A couple things to keep in mind while modifying Config.groovy:

1) Unlike the flat format used by log4j, the Grails config format is hierarchical, so if you write:

grails.app.controller.YourController="debug,stdout"
grails="info,stdout"
You're actually overriding the first setting with the second. To get around this you have to quote the first:
grails.'app.controller.YourController'="debug,stdout"
grails="info,stdout"
2) If you're not using the 'quote' format shown above you must always define children before parents in the Config.groovy file. For example, putting a parent before a child as shown below will result in an error:

grails.app="info,stdout"
grails.app.controller="debug,stdout"

Reversing the lines will eliminate the error (but the definition of grails.app will override the definition of grails.app.controller):

grails.app.controller="debug,stdout"
grails.app="info,stdout"

But After I fix it,it sitll can not doesn't work.then I google again and again.finally,
I found there are something error in default generate from Grails.
we should change following line
logger
{
grails.'app.controller.UserController'='warn,access'
}
instead of like this:
logger.
logger.grails.'app.controller.UserController'='warn,access'

now it's work well done.

No comments: