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"

}

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

4

2 回答 2

1

如果您想停用对特定附加程序的所有日志记录,您可以通过设置附加程序的阈值来实现

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.

于 2013-01-26T15:00:38.927 回答
0

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

root {
    info 'connections', 'view'
}

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

要激活,然后更改offinfo

info connections: 'grails.app.controllers.ViewController'
于 2013-01-26T10:25:29.500 回答