Grails应用程序中没有log4j输出

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)

有关日志记录的Grails用户指南部分略有说明.


Rob*_*anu 9

由于grails将委托记录到log4j,您可以使用-Dlog4j.debug并查看log4j的配置方式(引用).也许是另一个文件.


至少有一个针对日志记录的关键错误修复,目标是1.2而不是1.1.x. 配置与您的配置类似.也许消息被错误地记录在不同的文件中?