Marks Blog
  • PowerDNS Admin
  • About
  • Simple Ticket System

Grails remote logging with Graylog

January 29, 2016 by mark

I have a small Grails (2.5.x) web-application running on the AWS Elastic Beanstalk service. This works really well, but accessing log-files and debugging errors can be difficult. Therefor I decided to send some of the logging to a remote Graylog server (hosted elsewhere at the moment, but could just as well be running on an EC2 instance). If you are setting up your own Graylog server, be aware that the current stable version requires Elasticsearch 1.x and does not support version 2.x. Besides that the installation was easy and straightforward on Ubuntu 14.04. Before you are able to receive any messages you must add a Gelf UDP (or TCP) listener.

We must add support for the GELF appender (Graylog Extended Log Format) for log4j to our Grails project. Add the following into the dependencies section in conf/BuildConfig.groovy:

runtime 'org.graylog2:gelfj:1.1.13'

Next we must configure Grails to use the GELF Appender and send logging in that direction. In conf/Config.groovy in the log4j configuration add something like this:

// log4j configuration
log4j.main = {

    // Setup the Gelf log4j appender
    appender new org.graylog2.log.GelfAppender(
        name: 'gelfAppender',
        graylogHost: 'my.graylog.server,
        graylogPort: 12201,
        extractStacktrace: true,
        includeLocation: true,
    )

    // Example: log all messages from my.package to Gelf
    all gelfAppender: 'my.package'

    // Example: log hibernate errors to Gelf
    error gelfAppender: 'org.hibernate'
  }

And now log messages should show up in the Graylog webinterface if everything was setup correctly :)

Posted in: Grails Tagged: beanstalk, grails, graylog, logging

Weather Station

Pages

  • About
  • PowerDNS Admin
  • Simple Ticket System

Affiliates

  • Danish Sensor Engineering
  • Mintr ApS
  • Nellemann Data

Social

  • BitBucket
  • GitHub
  • LinkedIn
  • Mastodon

Categories

  • Android
  • Automobile
  • Blog & Rantings
  • Development & Scripting
  • Grails
  • Linux & Unix
  • Mac OS X
  • Misc
  • No category
  • PowerDNS Admin
  • Puppet
  • Security Related
  • VirtualBox
  • Virtualization
  • VMware
  • Windows

Archives

  • January 2019
  • September 2017
  • January 2016
  • May 2015
  • March 2015
  • February 2015
  • December 2014
  • October 2014
  • September 2014
  • August 2014
  • June 2014
  • January 2014
  • July 2013
  • June 2013
  • February 2013
  • January 2013
  • December 2012
  • August 2012
  • May 2012
  • October 2011
  • April 2011
  • February 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • March 2010
  • October 2009
  • September 2009
  • April 2009
  • January 2009
  • March 2008
  • January 2008
  • November 2007
  • January 2007
  • December 2006
  • November 2006
  • August 2006
  • June 2006
  • March 2006
  • October 2005
  • August 2005

Copyright © 2025 Marks Blog.

Mobile WordPress Theme by themehall.com