0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Ship json encoded log4r messages to logstash.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
~> 10.0
~> 3.1
~> 0.28

Runtime

~> 1.1
~> 3.2
~> 2.0
 Project Readme

log4r-logstash

log4r-logstash allows you to send Log4r logevents to Logstash with json encoding. It currently only supports a redis transport, but could easily be extended to other transports based on need.

Installation

Add this line to your application's Gemfile:

gem 'log4r-logstash'

And then execute:

$ bundle

Or install it yourself as:

$ gem install log4r-logstash

Usage

Log = Log4r::Logger.new("outofthebox")        # create a logger
Log.add Log4r::Logstash::RedisOutputter.new("redis")
Log.debug("test")
# : Sends the following json to 127.0.0.1:6379
# {
#   "type":"Log4r::LogEvent",
#   "index":"logstash",
#   "level":"DEBUG",
#   "data":"test",
#   "timestamp":"2015-01-27T19:44:29Z"
# }

Send to redis running on another host

Log.add Log4r::Logstash::RedisOutputter.new("redis", host: "myredisserver.mydomain.com")

Specify an index name

Log.add Log4r::Logstash::RedisOutputter.new("redis", index: "my_index")

You can override many of the default field names to match your conventions

Log.add Log4r::Logstash::RedisOutputter.new("redis",
                                            level_field_name: "LEVEL"
                                            data_field_name: "MESSAGE")
# {
#   "type":"Log4r::LogEvent",
#   "index":"logstash",
#   "LEVEL":"DEBUG",
#   "MESSAGE":"test",
# }

Add extra fields as necessary for your application. These will be passed straight through in the json as top level key-value pairs.

Log.add Log4r::Logstash::RedisOutputter.new("redis", additional_fields: {
                                                       foo: "bar",
                                                       goo: "baz"
                                                       time: -> { Time.now.getutc.rfc822 }
                                                     })
# {
#   "type":"Log4r::LogEvent",
#   "index":"logstash",
#   "level":"DEBUG",
#   "data":"test",
#   "timestamp":"2015-01-27T19:44:29Z"
#   "foo":"bar"
#   "goo":"baz"
#   "time":"Wed, 27 Jan 2015 19:44:29 -000"
# }

Contributing

  1. Fork it ( https://github.com/Cimpress-MCP/log4r-logstash/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

You can spin up a local redis instance in virtualbox using the included Vagrantfile by typing vagrant up. Monitor incoming messages using vagrant ssh -c "redis-cli monitor".

Run a simple example with ruby examples/redis.rb