Please use some other gem like LogstashLogger.
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.
- 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
Tested under CRuby 1.9.3 and 2.0 . See travis builds for more details.
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.
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.
LogstashRails.config
takes 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
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
.
- Fork it.
- Create a branch (
git checkout -b my_feature
) - Commit your changes (
git commit -am "Added ..."
) - Push to the branch (
git push origin my_feature
) - Open a Pull Request
- Enjoy a refreshing Orangina and wait
Licensed under the GNU General Public License version 3 (GPLv3). See LICENSE.txt for details.