2014-02-06 65 views
7

我正在開發grails 2.3.4應用程序,並且有一些日誌記錄問題。 實際上,我根本無法配置任何日誌記錄(因此爲http://grails.org/doc/latest/guide/conf.html#logging) - 沒有輸出結果。Grails日誌記錄不起作用

經過一番頭腦風暴後,我發現,grails文檔配置不適用於我的項目。然而,一些CONFIGS變化工作的罰款(我看到屏幕上的結果):

log4j = { 

appenders { 
    console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n') 
} 

root { 
    error 'stdout' 
    additivity = true 
} 

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' 

debug stdout: ['edu.dm'] 

}

的CONFIGS像:

debug stdout: ['grails.app.services', 'grails.app.services.edu'] 
debug stdout: ['grails.app.controllers', 'grails.app.controllers.edu'] 

失敗。

如果有人能解釋我的錯誤或與解釋共享鏈接,我將非常感激。 整個項目可以在這裏找到:https://github.com/AlexDavljatov/EduDM/tree/master/LoggingMiniProject

非常感謝提前。

親切的問候, 亞歷山大Davliatov。

+0

我不能立即發現問題。但是,這篇文章(儘管已經過了幾年)對我來說是一個有用的參考:http://6by9.wordpress.com/2010/12/07/grails-1-3-5-log4j-dsl/ –

回答

4

開始是這樣的:

log4j = { 
    root { 
     debug() 
    } 
} 

你應該得到了很多記錄到您的控制檯。然後,(如果適用),試試這個:

log4j = { 
    info "grails.app" 
} 

在你應該看到你的控制器和服務log.info輸出。然後慢慢地添加到配置中。

不要忘記在Config.groovy之間的變化之間重新啓動。 Grails的2.3.5項目

+0

感謝您的回答。 我已經嘗試了這種方法,並得到了很多東西。這些東西是關於資源,taglibs的......但是沒有記錄我的控制器/服務。 正如我上面提到的, debug'grails.app.controllers' debug'grails.app.services' 無法正常工作。 –

1

這種配置工作

// log4j configuration 
log4j = { 
appenders { 
    // Use if we want to prevent creation of a stacktrace.log file. 
    'null' name:'stacktrace' 

    // Use this if we want to modify the default appender called 'stdout'. 
    console name:'stdout', layout:pattern(conversionPattern: '%d{yyyy-MM-dd HH:mm} -%x- %-5p-%-10c:%m%n') 

    // Custom log file. 
    /* rollingFile name:"appLog", 
    file:"${globalDirs.logDirectory}${appName}.log".toString(), 
    maxFileSize:'300kB', 
    maxBackupIndex:1, 
    layout:pattern(conversionPattern: '%d{[EEE, dd-MMM-yyyy @ HH:mm:ss.SSS]} [%t] %-5p %c %x - %m%n')*/ 
} 

// This is for the built-in stuff and from the default Grails-1.2.1 config. 
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' // Jetty 

error 'grails.app' // Set the default log level for our app code. 

// Move anything that should behave differently into this section. 
switch(Environment.current) { 
    case Environment.DEVELOPMENT: 
    // Configure the root logger to output to stdout and appLog appenders. 
     root { 
      error 'stdout' 
      //,'appLog' 
      additivity = true 
     } 
     error 'grails.plugin.springsecurity.web.filter.DebugFilter' 
     error "grails.plugins.twitterbootstrap" 
     debug "it.mypackage" 
      debug "org.hibernate.SQL" 
     debug 'grails.app.controllers' 
      debug 'grails.app.services' 
     debug 'grails.app.taglib' 
     debug 'grails.app.conf' 
     debug 'grails.app.jobs' 
     break 
    case Environment.TEST: 
    // Configure the root logger to only output to appLog appender. 
     root { 
      error 'stdout' 
      //,'appLog' 
      additivity = true 
     } 
    //depend how much code write in console 
      //   debug 'grails.app.controllers' 
    //   debug 'grails.app.domain' 
    //   debug 'grails.app.services' 
    //   debug 'grails.app.taglib' 
    //   debug 'grails.app.conf' 
    //   debug 'grails.app.filters' 
     break 
    case Environment.PRODUCTION: 
    // Configure the root logger to output to stdout and appLog appenders. 
     root { 
      error 'stdout' 
      //,'appLog' 
      additivity = true 
     } 
    error 'grails.app' 
     break 
} 
} 
1

對於你的Grails版本(2.3.4 http://grails.github.io/grails-doc/2.3.4/guide/conf.html#logging)似乎問題是你繼承從根配置級別。 爲了避免這種情況,你需要指定可加性:假

log4j = { 
    ... 
    debug additivity: false, stdout: ['grails.app.services', 'grails.app.services.edu', 'grails.app.controllers', 'grails.app.controllers.edu'] 
    ... 
}