开发者

How do I get an injected logger to work in grails?

开发者 https://www.devze.com 2023-02-03 21:14 出处:网络
I\'m an absolute beginner at grails and I\'m stumbling on something that should be easy. I\'ve been looking at this page on controller dynamic methods and I see logging on there. How do I enable my co

I'm an absolute beginner at grails and I'm stumbling on something that should be easy. I've been looking at this page on controller dynamic methods and I see logging on there. How do I enable my controller to receive an injected logger开发者_Go百科? So, far this is all that my controller has:

package my.app

class LinkRewritterController {
    def index = { }

    // How do make the injected logger work?
    def logMe() {
        log.debug "Foo value"
    }
}

What am I missing?


You have a logger injected, otherwise you'd get a null pointer exception or missing property exception on the log.debug line. But you can't see debug messages since they're below the threshold. Avoid the random wiki pages at grails.org and use the reference manual instead: http://grails.org/doc/latest/ and in particular look at section 3.1.2 on Logging: http://grails.org/doc/latest/guide/3.%20Configuration.html#3.1.2%20Logging

There's also an updated version here that's got more information: http://people.apache.org/~pledbrook/grails-guide/guide/3.%20Configuration.html#3.1.2%20Logging

To see debug messages for this controller, add this line to the log4j closure in grails-app/conf/Config.groovy:

log4j = {
   ...
   debug 'grails.app.controller.my.app.LinkRewritterController'
}
0

精彩评论

暂无评论...
验证码 换一张
取 消