是否可以激活|通过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"
}
如何停用所有“连接”记录器?
答案 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'