Grails Runtime Logging Plugin

  • Tags: performance, utility
  • Latest: 0.4
  • Last Updated: 30 January 2012
  • Grails version: 1.3 > *
1 vote
Dependency:
compile ":runtime-logging:0.4"

 Documentation  Source

Summary

Allows you to change the logging characteristics (e.g. Level) for common parts of a Grails application at runtime without the need to restart.

Description

Runtime Logging (log4j) Plugin

This plugin allows you to easily control log4j logging at runtime, using a simple GUI interface, without the need to restart your application.

NOTE: This is still an alpha release, and should be treated as such. Specifically, beware of releasing it into production as-is, because there is currently no authentication/protection around the function. But see the "Authentication" section below.

Plugin features:

  • Simple GUI interface for controlling log4j settings
  • Dynamically change log4j settings without need to restart
  • Separately control common parts of the application such as Controllers, Services, SQL etc.
  • Uses intuitive names like "SQL", "Services", "Controllers" (rather than class names) to make it easier for newbies.
  • Displays the equivalent closure to add to Config.groovy to get the same effect permanently
The plugin provides a simple GSP/Controller which lets you pick a common part of the application (e.g. "Controllers", "Services", "SQL") and the desired logging level ("DEBUG","ERROR" etc) on-screen.

Full source code is included in the plugin.

Setup

Install by adding a dependency in BuildConfig.groovy (be sure to update the version to the latest):

plugins {
   …
   compile ':runtime-logging:0.4'
}

After install test it by going to this page:

http://localhost:8080/app/runtimeLogging

Try setting "SQL" to "DEBUG" and click Submit. All SQL statements should now be logged. You will also see some "Groovy Equivalent" code - copy/paste this into Config.groovy to achieve the same effect permanently.

Authentication

The plugin comes with no authentication or security out-of-the-box. Do not use it in production as-is because anyone could switch on logging to maximum and eat all your disk space and probably crash the server.

You should use a security plugin, either Spring Security Core or Shiro. If you're using Spring Security Core the approach is different depending on which authentication approach you're using. If you have Requestmap instances in the database, add a new one, e.g.

new RequestMap(url: '/runtimelogging/**', configAttribute: 'ROLE_ADMIN').save()

If you're using annotations, add the rule to the staticRules property in Config.groovy, e.g.

grails.plugins.springsecurity.controllerAnnotations.staticRules = [
   '/runtimelogging/**': ['ROLE_ADMIN']
]

And if you're using the "interceptUrlMap" approach, add a rule to that map in Config.groovy:

grails.plugins.springsecurity.interceptUrlMap = [
   …
   '/runtimelogging/**':    ['ROLE_ADMIN']
]

Using a filter for security isn't a good idea, but it is an option. If you want to use this approach you could use code similar to this:

class MyFilters {
   def filters = {
      authFilter(controller:"runtimeLogging",action:"*") {
         before = {
            // Define your own isAllowed() logic
            if (!isAllowed()) {
               render "You Are Not Authorised"
               return false
            }		
            return true
         }
      }
   }
}

Future plans

  • Add authentication
  • Add configuration to allow user-controlled categories
  • Add environment-specific config so function can be enabled/disabled for production

Release Notes

  • v.0.3: Changes submitted by Brad Whitaker add dynamic selectors to allow more granular control of each Controller/Domain/Service present in the application.
  • v.0.4: Updated to work with Grails 1.3 and 2.0.

Questions

Contact jason.morris@torusit.com