LogstashRails

Gem Version Build Status Coverage Status Code Climate Dependency Status

Send events from Rails to Logstash without logger foo.

LogstashRails uses ActiveSupport::Notifications to subscribe to events from Rails and push them to Logstash. It emmits json formatted Logstash::Event.

There is no Logger configuration, logfile or filter in Logstash required.

Contents

Usage

Add logstash-rails to your applications Gemfile

gem 'logstash_rails'

and provide an initializer for configuration.

You will have to add redis as a dependency to your application in order to use the redis transport.

Configuration

LogstashRails.config takes an options hash with the following options:

transport

redis, logstash-udp, logstash-tcp and logfile are available

events

list of event name patterns to subscribe to. Regex and String is supported.

flatten_params

true or false, defaults to false

flatten the params hash of process_action.action_controller events. This gets rid of collisions in dynamic mappings in ElasticSearch

logger

logger to use in case of exceptions while pushing events to the transport

transport specific options

should be self explaining

redis:

  • host
  • port
  • redis_key

logfile:

  • logfile

logstash-tcp:

  • host
  • port

logstash-udp:

  • host
  • port

Examples

The most basic configuration looks like:

LogstashRails.config(transport: :redis)

This will connect to a redis server on localhost:6379, use logstash as key for the redis list to push to and subscribe to all events.

A more complete example looks like:

if Rails.env.production?
  LogstashRails.config(
    transport: :redis,
    host: '1.2.3.4',
    port: 12345,
    redis_key: 'my_key',
    events: [/action_controller/]
  )
end

This will only subscribe to events from ActionController.

Contributing

  1. Fork it.
  2. Create a branch (git checkout -b my_feature)
  3. Commit your changes (git commit -am "Added ...")
  4. Push to the branch (git push origin my_feature)
  5. Open a Pull Request
  6. Enjoy a refreshing Orangina and wait

License

Licensed under the GNU General Public License version 3 (GPLv3). See LICENSE.txt for details.