grails log4j活动记录器

时间:2013-01-25 17:15:39

标签: grails groovy log4j grails-2.0

是否可以激活|通过Config.groovy?

停用记录器

代表:

log4j = {

    appenders {

        file name:'connections', file: '/tmp/connection.log'
        file name:'view', file:'/tmp/view.log'
    }

    root {
        off 'connections', 'view'
    }


    info connections: "grails.app.controllers.ViewController",
            consultations: "grails.app.controllers.ConnectController"

}

如何停用所有“连接”记录器?

2 个答案:

答案 0 :(得分:1)

如果要取消激活对特定appender的所有日志记录,可以通过设置appender的阈值

来执行此操作
log4j = {
    appenders {
        file name:'connections', file: '/tmp/connection.log',
             threshold:org.apache.log4j.Level.OFF

但即使没有记录任何内容,这仍然会创建connection.log文件。另一种方法是利用log4j DSL是Groovy代码的事实:

log4j = {
    appenders {
        if(config.log.connections) {
            // use a file appender for 'connections'
            file name:'connections', file: '/tmp/connection.log'
        } else {
            // use a NullAppender, which simply ignores anything it is
            // asked to log
            'null' name:'connections'
        }

这样您就可以使用

切换“连接”日志
log.connections=true

Config.groovy的主要部分(在log4j闭包之外)或在您使用grails.config.locations引用的外部文件中。

答案 1 :(得分:0)

要停用,请尝试以下操作:

root {
    info 'connections', 'view'
}

off connections: 'grails.app.controllers.ViewController'

要激活,请将off更改回info

info connections: 'grails.app.controllers.ViewController'