0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Send events from Rails to Logstash without logger foo.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

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
  • Platforms
  • Usage
    • API
    • Configuration
    • Examples
  • Contributing

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.