Dominik Feininger
Dominik Feininger

Reputation: 456

grails server log

I am very new to Grails. I uses to work a little bit with Ruby.

I made an iOs app which communicates with the grails backend. Now I have the problem that I can't see what exactly the server receives.

I am searching for the development.log file. Or a way to see what my server receives and sends as well as the logs entries.

I develop in NetBeans IDE 7.1.2 and Grails 2.1.

thx

Upvotes: 1

Views: 560

Answers (2)

rdmueller
rdmueller

Reputation: 11062

If you use tomcat as sever, just enable the access log valve and you'll get a log with all requests: http://tomcat.apache.org/tomcat-5.5-doc/config/valve.html#Access_Log_Valve

Upvotes: 2

Kelly
Kelly

Reputation: 3709

I'm doing something very much like you are doing. I created a separate log file just for the mobile app. I'm going to include my entire log4j section in the Config.groovy to make it easier to understand. This will create 4 appender logs in /var/log/grails/ - an error, warn, info and mobileApp log; change that as you require.

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"
}

Then when I need to use my mobileAppLog in the controller do the following:

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")

Upvotes: 0

Related Questions