/logstash_rails

Primary LanguageRubyGNU General Public License v3.0GPL-3.0

DEPRECATED

Please use some other gem like LogstashLogger.

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

Features

  • fine grained control over which events will be subscribed to
  • some json event format normalization to prevent troubles with Elasticsearch
  • can be reconfigured at runtime
  • tcp and udp transports for testing

Platforms

Tested under CRuby 1.9.3 and 2.0 . See travis builds for more details.

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.

API

LogstashRails.configure(options_hash) returns an configured instance of LogstashRails::Transport. See Configuration for the options.

LogstashRails::Transport#destroy releases all resources (e.g. closes sockets) and unsubscribes from all events for this instance.

Configuration

LogstashRails.configtakes an options hash with the following options:

transport

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

logstash-tcp and logstash-udp should only be used for testing since they produce significant runtime overhead.

events

list of event name patterns to subscribe to. Regex and String is supported. Defaults to [/.*/]

See Active Support Instrumentation for the events that Rails emmits.

flatten_params

true or false, defaults to true

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: :logfile)

This will write all events to APP_ROOT/log/logstash_rails.log

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.