2009-06-02 54 views
11

没有log4j的输出I具有以下log4j的配置在我的Grails 1.1应用Grails中应用

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下试过日志类,但是这似乎并没有什么差别

谢谢, 唐

回答

17

唐,

如果您尝试登录的类是标准的Grails类(域控制器,服务等),你应该能够使用类似:

​​

有一个在Grails的用户指南稍微描述section on logging.

-1

唐,

我还没有完全破解的复杂性在1.1中记录DSL,但这可能对您有用:动态日志记录插件允许您在应用程序启动时打开/关闭日志记录通道,并生成一些配置文件,然后将其放入Conf.groovy。

希望这会有所帮助。

9

由于grails日志记录委托给log4j,因此可以使用-Dlog4j.debug并查看log4j如何配置(reference)。也许另一个文件被拾起。


至少有一个critical bug fix用于日志记录,目标是1.2而不是1.1.x.配置与您的配置类似。也许这些消息被错误地记录在不同的文件中?

0

你需要在单元测试中注入记录到您的控制器:

mockLogging(<controller class name>, true) 

第二个参数表示记录调试消息和以下。