Project

General

Profile

Sending Foreman logs to a remote system using GELF » History » Version 2

Johan Sunnerstig, 03/04/2015 08:41 AM

1 1 Johan Sunnerstig
h1. Sending Foreman logs to a remote system using GELF
2
3
h2. GELF
4 2 Johan Sunnerstig
5 1 Johan Sunnerstig
GELF is the Graylog Extended Log Format, a JSON based format. Read more about the format itself here:
6
https://www.graylog.org/resources/gelf-2/
7
8
h2. Setting Foreman up to send logs to Graylog(or anything that can interpret GELF)
9 2 Johan Sunnerstig
10 1 Johan Sunnerstig
h3. Installing the gelf gem
11
Firstly you need the 'gelf' ruby gem. Add the following line to the file '_~foreman/bundler.d/gelf.rb_'
12
<pre><code class="ruby">
13
gem 'gelf', '1.4.0'
14
</code></pre>
15
16
Now run '_su - foreman -c bundle_' to install the gem and any dependencies. When it's done you should see a line like so:
17
_Your bundle is complete! It was installed into ./vendor_
18
19
h3. Updating your configuration
20
Now it's time to make Foreman use it. Edit '_~foreman/config/environments/production.rb_' and find the line with a logger example.
21
You need to add one of your own like this:
22
<pre><code class="ruby">
23
  # Use a different logger for distributed setups
24
  # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
25
  config.logger = GELF::Logger.new("your.graylog.server.com", 12201, "WAN", { :facility => "foreman" })
26
</code></pre> 
27
The facility field can be (almost) anything you feel like, preferably something descriptive.
28
29
Now restart your Foreman instance and you should be good to go.