Lennart Koopmann

{ :blog => true }

Tag Results

1 post tagged rack

Easily log all your Rails Exceptions to Graylog2

I wrote and published a gem that you can load as Rack middleware in your Rails application. It transparently fetches all your Exceptions (and throws them back to the application so it does not affect your own Exception handling) and sends them as a GELF message to your Graylog2 installation.

Installation

Install the gem. It has my GELF gem as dependency and will install it automatically:

lennart ~$ sudo gem install graylog2_exceptions
Successfully installed gelf-0.9.1
Successfully installed graylog2_exceptions-0.5.3

Now open your config/environment.rb and add the gem as Rack middleware: (Make sure to require 'graylog2_exceptions' before.)

config.middleware.use "Graylog2Exceptions", { :host => '127.0.0.1', :port => '12201', :local_app_name => 'mama' }

Parameter explanation:

  • host: The hostname or IP of your Graylog2 server
  • port: The GELF port your Graylog2 server is listening on (Standard: 12201)
  • local_app_name: This name will be used as “host” field (Optional)
  • level: The syslog level for all Exceptions (Optional)

That’s it: Restart your app and all your Exceptions will be logged to Graylog2!

(Source code of the gem at GitHub)