Project

General

Profile

Actions

Sending Foreman logs to a remote system using GELF

GELF

GELF is the Graylog Extended Log Format, a JSON based format. Read more about the format itself here:
https://www.graylog.org/resources/gelf-2/

Setting Foreman up to send logs to Graylog(or anything that can interpret GELF)

Installing the gelf gem

Firstly you need the 'gelf' ruby gem. Add the following line to the file ~foreman/bundler.d/gelf.rb

gem 'gelf', '1.4.0'

Now run su - foreman -c bundle to install the gem and any dependencies. When it's done you should see a line like so:
Your bundle is complete! It was installed into ./vendor

Updating your configuration

Now it's time to make Foreman use it. Edit ~foreman/config/environments/production.rb and find the line with a logger example.
You need to add one of your own like this:

  # Use a different logger for distributed setups
  # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
  config.logger = GELF::Logger.new("your.graylog.server.com", 12201, "WAN", { :facility => "foreman" })

The facility field can be (almost) anything you feel like, preferably something descriptive.

Now restart your Foreman instance and you should be good to go.

Updated by Johan Sunnerstig over 9 years ago · 5 revisions