Valeriane
Valeriane

Reputation: 954

grails log4j active logger

Is it possible to activate | deactivate logger through Config.groovy?

for ex:

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"

}

How I can deactivate all 'connections' logger?

Upvotes: 0

Views: 190

Answers (2)

Ian Roberts
Ian Roberts

Reputation: 122364

If you want to de-activate all logging to a particular appender you can do that by setting the appender's threshold

log4j = {
    appenders {
        file name:'connections', file: '/tmp/connection.log',
             threshold:org.apache.log4j.Level.OFF

but this will still create the connection.log file even though nothing is to be logged to it. An alternative would be to take advantage of the fact that the log4j DSL is Groovy code:

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'
        }

This would let you switch 'connection' logging on or off using

log.connections=true

in the main part of Config.groovy (outside the log4j closure) or in an external file you have referenced using grails.config.locations.

Upvotes: 1

chanwit
chanwit

Reputation: 3214

To deactivate, try this:

root {
    info 'connections', 'view'
}

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

To activate, then change off back to info:

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

Upvotes: 0

Related Questions