(Quick Reference)

8 Troubleshooting - Reference Documentation

Authors: Burt Beckwith

Version: 1.2.3

8 Troubleshooting

You can enable logging of the JSON responses from client calls by setting the grails.plugin.cloudfoundry.Scripts category to the debug level in your log4j configuration, e.g.

debug 'grails.plugin.cloudfoundry.Scripts'

You can also log all client method calls with

trace 'grails.plugin.cloudfoundry.ClientWrapper'

There is also some logging from the cloud-support plugin and the Cloud Foundry java client, so adding this configuration would log all messages:

trace 'grails.plugin.cloudfoundry'
trace 'grails.plugin.cloudsupport'
trace 'org.cloudfoundry'

Some exceptions will always show a stack trace, but others are somewhat expected and just the error messages are displayed, but you can print all stacktraces by adding this to Config.groovy

grails.plugin.cloudfoundry.showStackTrace = true

console and dbconsole plugins

The console and dbconsole plugins are very helpful in diagnosing issues. The console plugin allows you to run arbitrary Groovy code from a web-based console (similar to the Grails/Groovy Swing-based console) and the dbconsole plugin exposes the H2 database's web-based database console (the H2 database console is available in Grails 2.0 by default, so you only need the plugin in pre-2.0 apps). The great thing about H2's database console is that it doesn't work for just H2 - it works for any JDBC database you have a driver for.

These plugins are very dangerous if left exposed to the public. Be sure to guard them with security if you use them.

One issue you'll see is that it's tricky to know how to connect to your Cloud Foundry MySQL/PostgreSQL database from the database console. You can use the console plugin to inspect the config settings, but it's more convenient to add this code to your application's BootStrap.groovy:

import grails.converters.JSON

class BootStrap {

def init = { servletContext -> String VCAP_SERVICES = System.getenv('VCAP_SERVICES') println "VCAP_SERVICES: ${System.getenv('VCAP_SERVICES')}n"

try { def servicesMap = JSON.parse(VCAP_SERVICES) servicesMap.each { key, services -> if (key.startsWith('mysql')) { for (service in services) { print "MySQL service $service.name: " print "url='jdbc:mysql://$service.credentials.hostname:$service.credentials.port/$service.credentials.name', " print "user='$service.credentials.user', " println "password='$service.credentials.password'n" } } else if (key.startsWith('postgresql')) { for (service in services) { print "PostgreSQL service $service.name: " print "url='jdbc:postgresql://$service.credentials.hostname:$service.credentials.port/$service.credentials.name', " print "user='$service.credentials.user', " println "password='$service.credentials.password'n" } } } } catch (e) { println "Error occurred parsing VCAP_SERVICES: $e.message" } } }

Note that this code is modified from this project.

If you are using Grails 2.0 or higher you can enable the database console in Config.groovy with the grails.dbconsole.enabled attribute (it's only enabled by default in development):

environments {
   production {
      grails.dbconsole.enabled = true
   }
   …
}

and you can also customize the URL root with the grails.dbconsole.urlRoot attribute:

environments {
   production {
      grails.dbconsole.enabled = true
      grails.dbconsole.urlRoot = '/admin/dbconsole'
   }
   …
}

One the application starts up you can view the output by running

grails cf-logs --stdout

or by using the file view in the Cloud Foundry UI plugin.