在执行集成测试时,我一直在努力争取显示日志消息(无论是文件还是控制台)。我假设我可以使用以下代码添加日志消息:
log.debug "Some useful information here"
我在_GrailsWar.groovy
中注释了以下一行:
target(startLogging:"Bootstraps logging") {
// do nothing, overrides default behaviour so that logging doesn't kick in
}
正如http://jira.codehaus.org/browse/GRAILS-4470
所建议的那样 Config.groovy
的log4j部分如下所示:
// log4j configuration
log4j = {
// Example of changing the log pattern for the default console
// appender:
//
appenders {
//console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n
//console name: 'stdout', layout: pattern(conversionPattern: '%d{dd-MM-yyyy HH:mm:ss,SSS} %5p %c{1} - %m%n')
//file name: 'hibeFile', file: 'hibe.log', layout: pattern(conversionPattern: '%d{dd-MM-yyyy HH:mm:ss,SSS} %5p %c{1} - %m%n')
file name:'file', file:'C:/Users/Christopher/Documents/NetBeansProjects/TestProject/smyh.log', append: false
console name:'stdout'
}
error 'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web.pages', // GSP
'org.codehaus.groovy.grails.web.sitemesh', // layouts
'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
'org.codehaus.groovy.grails.web.mapping', // URL mapping
'org.codehaus.groovy.grails.commons', // core / classloading
'org.codehaus.groovy.grails.plugins', // plugins
'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
'org.springframework',
'org.hibernate',
'net.sf.ehcache.hibernate'
warn 'org.mortbay.log'
debug 'grails.app'
info 'grails.app'
root {
// change the root logger to my tomcatLog file
error 'file', stdout
info 'file', stdout
warn 'file', stdout
debug 'file', stdout
additivity = true
}
}
有没有人知道为什么在集成测试期间我看不到我的日志消息?
非常感谢你的时间。
答案 0 :(得分:6)
我终于找到了解决自己问题的方法。为了记录集成测试,我在顶部附近添加了以下行:
import org.apache.commons.logging.LogFactory
然后在课堂上我添加了以下内容:
def log = LogFactory.getLog(getClass())
这来自:http://grails.1312388.n4.nabble.com/Problems-with-Logging-td1360669.html
然后我可以进行记录,例如
log.debug('*** It works! ***');
答案 1 :(得分:0)
查看用户邮件列表中的this recent thread 您可能遇到the same issue?
编辑:嗯,这可能就是你已经做过的事,抱歉。