Skip to content

Additional adapters gelf

rudionrails edited this page Jun 29, 2012 · 4 revisions

Graylog2 (GELF) Adapter

The GELF adapter for Yell is available as separate gem.

Installation

System wide:

gem install yell-adapters-gelf

Or in your Gemfile:

gem "yell-adapters-gelf"

Since the yell is a gem dependency, it will be installed automatically with it.

Usage

After you set-up Graylog2 accordingly, you may use the Gelf adapter just like any other.

logger = Yell.new :gelf

# or alternatively with the block syntax
logger = Yell.new do |l|
  l.adapter :gelf
end

logger.info 'Hello World!'

Now check your Graylog2 web server for the received message. By default, the gelf adapter will send the following information to Graylog2:

facility: The GELF facility (default: 'yell')
level: The current log level
timestamp: The time when the log event occured
host: The current hostname
file: The name of the file where the log event occured
line: The line in the file where the log event occured
_method: The method where the log event occured
_pid: The PID of your current process

Example: Running with a different GELF facility

logger = Yell.new :gelf, :facility => 'my own facility'

# or with the block syntax
logger = Yell.new do |l|
  l.adapter :gelf, :facility => 'my own facility'
end

Example: Running Graylog2 on a different host or port

logger = Yell.new :gelf, :host => '127.0.0.1', :port => 1234

# or with the block syntax
logger = Yell.new do |l|
  l.adapter :gelf, :host => '127.0.0.1', :port => 1234
end

logger.info 'Hello World!'

Example: Passing additional keys to the adapter

logger = Yell.new :gelf

logger.info "Hello World", "_thread_id" => Thread.current.object_id, 
                           "_current_user_id" => current_user.id

If you are savvy with how Graylog2 works you can pass in any keys (even the pre-defined ones)

logger = Yell.new :gelf

logger.info 'short_message' => 'Hello World', 'long_message' => 'Really long message'