我的 Grails 1.1 应用程序中有以下 log4j 配置
log4j = {
// Enable Hibernate SQL logging with param values
trace 'org.hibernate.type'
debug 'org.hibernate.SQL'
debug 'com.mycompany'
appenders {
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')
}
// By default, messages are logged at the error level to both the console and hibe.log
root {
error 'stdout', 'hibeFile'
additivity = true
}
}
当我运行单元测试时,生成的唯一日志记录输出来自 Hibernate 类。我不明白为什么我自己的类(即 com.mycompany
命名空间下的类)没有生成日志输出。奇怪的是,当我运行集成测试时,log4j 输出符合预期。
如果我转到单元测试的测试报告,然后单击“System.out”链接,我会看到以下格式的日志消息:
DEBUG (member.InviteServiceTests): Calling getInvite with member (4517)
请注意,这与我在 log4j 配置中指定的模式不同。此外,如果我更改 log4j 配置:
debug 'com.mycompany'
至:
fatal 'com.mycompany'
我仍然在测试报告中看到调试级别的日志消息。运行单元测试时似乎根记录器被覆盖?我尝试使用单独的记录器在 com.mycompany
下记录类,但这似乎没有任何区别
谢谢, 唐
最佳答案
唐,
如果您尝试记录的类是标准 Grails 类(域、 Controller 、服务等),您应该能够使用如下内容:
log4j = {
// Logging warnings and higher for all of the app
warn 'grails.app'
// Logging infos and higher for all controllers
info 'grails.app.controller'
// Logging debug and higher for the BarService
debug 'grails.app.service.BarService'
appenders {
// ...as above...
}
root {
// ...as above...
}
}
Grails 用户指南 section on logging. 有更多描述
关于logging - Grails 应用程序中没有 log4j 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/940197/