2011-01-03 8 views
5

私は、統合テストを実行するときにログメッセージを(ファイルまたはコンソールのどちらかに)表示させようと数時間苦労しました。ここhttp://jira.codehaus.org/browse/GRAILS-4470統合テスト中のGrailsでのログ

のlog4jのセクション提案されているよう

target(startLogging:"Bootstraps logging") { 
// do nothing, overrides default behaviour so that logging doesn't kick in  
} 

:私は_GrailsWar.groovyに以下の行をコメントアウトしている

log.debug "Some useful information here" 

:私は、ログメッセージを追加するには、次のコードを使用することができます仮定しましたConfig.groovyは次のようになります。

// 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

ユーザーメーリングリストのthis recent threadをご覧ください。
おそらくthe same issueが発生していますか?

編集:まあ、それはおそらくあなたがすでにやったことです、申し訳ありません。

+0

ありがとうございます。私があなたが言及した特定のメーリングリストを見たことはありませんでしたが、_GrailsWar.groovyファイルを修正することを示唆するリンクを見つけました。私は残念ながらスレッドから解決策を見つけ出すことができませんでした。 –

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! ***'); 
+0

テストクラス内のコードに対してのみ機能します – pinei

関連する問題