Dón*_*nal 11 grails groovy logging log4j
我的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
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行单元测试时,生成的唯一日志输出来自Hibernate类.我不明白为什么没有为我自己的类生成日志输出,即com.mycompany
命名空间下的那些.奇怪的是,当我运行集成测试时,log4j输出正如预期的那样.
如果我转到单元测试的测试报告,然后单击"System.out"链接,我会看到以下格式的日志消息:
DEBUG (member.InviteServiceTests): Calling getInvite with member (4517)
Run Code Online (Sandbox Code Playgroud)
请注意,这与我在log4j配置中指定的模式不同.此外,如果我从以下位置更改log4j配置:
debug 'com.mycompany'
Run Code Online (Sandbox Code Playgroud)
至:
fatal 'com.mycompany'
Run Code Online (Sandbox Code Playgroud)
我仍然在测试报告中看到调试级别的日志消息.在运行单元测试时似乎正在覆盖根记录器?我已经尝试com.mycompany
使用单独的记录器记录类,但这似乎没有任何区别
谢谢,唐
jkl*_*jkl 17
唐,
如果您尝试记录的类是标准Grails类(域,控制器,服务等),您应该能够使用以下内容:
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...
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13272 次 |
最近记录: |