Java grails 中的 log4j:如何登录到文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1157159/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
log4j in grails : how to log into file?
提问by nightingale2k1
I have this log4j configuration in my grails config.groovy
我的 grails config.groovy 中有这个 log4j 配置
log4j = {
error 'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web.pages' // GSP
warn 'org.mortbay.log'
appenders {
rollingFile name:'infoLog', file:'info.log', threshold: org.apache.log4j.Level.INFO, maxFileSize:1024
rollingFile name:'warnLog', file:'warn.log', threshold: org.apache.log4j.Level.WARN, maxFileSize:1024
rollingFile name:'errorLog', file:'error.log', threshold: org.apache.log4j.Level.ERROR, maxFileSize:1024
rollingFile name:'custom', file:'custom.log', maxFileSize:1024
}
root {
info 'infoLog','warnLog','errorLog','custom', stdout
error()
additivity = true
}
}
the infoLog,warnLog and errorLog was from the previous question ... they were working well.
infoLog、warnLog 和 errorLog 来自上一个问题……它们运行良好。
now I add new RollingFile wit name "custom" ...
现在我添加新的 RollingFile 机智名称“自定义”...
I tried to log from my controller and service using log.info("something .... ${obj}"); but it seems that message was not inserted into custom.log, do I need to add something to the configuration ?
我尝试使用 log.info("something .... ${obj}") 从我的控制器和服务登录;但似乎消息没有插入 custom.log,我需要在配置中添加一些东西吗?
thank you !!
谢谢你 !!
采纳答案by nightingale2k1
just got answer from the grails' mailing list:
刚刚从 grails 的邮件列表中得到答案:
i just need to add
我只需要添加
debug "grails.app"
调试“grails.app”
bellow warn "org.mortbay.log"
波纹管警告“org.mortbay.log”
case closed ! :)
案件结案!:)
回答by Denis Wang
I have exact the same jetty/tomcat env's. Spent hours to figure it out. The trick is to define the file location (a relative path in my case) as a global variable inside Config.groovy, customized it in the environment blocks, and use the variable location inside log4j closure. Sample code is at: http://denistek.blogspot.com/2010/02/grails-environment-specific-logging-to.html
我有完全相同的码头/tomcat 环境。花了几个小时才弄明白。诀窍是将文件位置(在我的例子中是一个相对路径)定义为 Config.groovy 中的全局变量,在环境块中对其进行自定义,并在 log4j 闭包中使用变量位置。示例代码位于:http: //denistek.blogspot.com/2010/02/grails-environment-specific-logging-to.html
回答by Ford Guo
please see Log4j: How to write to a specific appender?
After all the solution is to put the additivity setting to the package configuration:
info specialLog:'activityLog', additivity:false
毕竟解决方案是将可加性设置放到包配置中:
info specialLog:'activityLog', additivity:false