2012-07-13 121 views
1

我對Grails非常陌生。我用Ruby來工作一點點。grails服務器日誌

我做了一個iOs應用程序,它與grails後端進行通信。現在我遇到了無法看到服務器接收到的問題。

我正在尋找development.log文件。或者查看我的服務器接收和發送的內容以及日誌條目。

我在NetBeans IDE 7.1.2和Grails 2.1中開發。

thx

回答

0

我正在做一件非常像你正在做的事情。我爲移動應用程序創建了一個單獨的日誌文件。我將在Config.groovy中包含我的整個log4j部分,以便更容易理解。這將在/var/log/grails/中創建4個appender日誌 - 錯誤,警告,信息和mobileApp日誌;根據需要更改。

log4j = { 
    appenders { 
     rollingFile name:'infoLog', file:'/var/log/grails/info.log', threshold: org.apache.log4j.Level.INFO, maxFileSize:"1MB", maxBackupIndex: 10 
     rollingFile name:'warnLog', file:'/var/log/grails/warn.log', threshold: org.apache.log4j.Level.WARN, maxFileSize:"1MB", maxBackupIndex: 10 
     rollingFile name:'errorLog', file:'/var/log/grails/error.log', threshold: org.apache.log4j.Level.ERROR, maxFileSize:"1MB", maxBackupIndex: 10 
     rollingFile name:'mobileAppLog', file:'/var/log/grails/mobile.log', threshold: org.apache.log4j.Level.INFO, maxFileSize:"1MB", maxBackupIndex: 10 
     //UNTESTED 
     rollingFile name:'debugLog', file:'/var/log/grails/debug', threshold: DEBUG, maxFileSize:"1MB", maxBackupIndex: 10 
    } 
    root { 
     info 'infoLog','warnLog','errorLog', stdout 
     error() 
     additivity = true 
    } 

    info mobileAppLog: 'mobileAppLog', additivity:false 

    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' 

    //UNTESTED - you could remove individual entries here to get less data 
    debug '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" 
} 

然後,當我需要用我的mobileAppLog控制器執行以下操作:

import org.apache.log4j.Logger 

//inside controller class 
def appLog = Logger.getLogger('mobileAppLog') 

//To actually write to the log 
appLog.info("whatever you need to write") 
+0

嗨,thx。但不是像完整的開發日誌那樣。服務器中的每個操作都會執行一個文件嗎?就像有人(如果在網站上或從外部無關)向控制器發送請求? – 2012-07-13 21:29:52

+0

我從來沒有嘗試過這個,但是你可以嘗試設置消息級別爲「debug」並創建一個調試日誌。你可能會得到大量的信息 - 就像我說過我從未這樣做過的。我會更新我的答案,以表明我將如何嘗試這一點。請記住,這是未經測試的... – Kelly 2012-07-13 21:48:51