Giter Club home page Giter Club logo

rails-logstasher's Introduction

RailsLogstasher

Build Status Coverage Status Code Climate Dependency Status

Logstash logging system for Ruby on Rails. This is a fork from https://github.com/rurounijones/yarder.

This gem will create JSON based log entries designed for consumption by Logstash version 1.2. The JSON will contain the same information as can be found in the default rails logging output.

Current Status

All logging in a Rails3 app should be JSON formatted, including ad-hoc logging.

RailsLogstasher has been tested against Rails 3.2.16 on Ruby 1.9.3.

Installation

Add this line to your Rails application's Gemfile:

gem 'rails-logstasher'

Configuration

RailsLogstasher uses the Rails logger (set using config.logger in application.rb)to log output.

By default Rails uses the TaggedLogging class to provide this however because RailsLogstasher replaces it you will need to change the default to something else.

You will need to specify a Ruby Logger compatible logger. RailsLogstasher provides its own logger which is a copy of the ActiveSupport::Logger (Formerly known as ActiveSupport::BufferedLogger)

If you are not sure what you want yet then set the RailsLogstasher::Logger as in the example below in your application.rb file.

module MyApp
  class Application < Rails::Application

    # Set a logger compatible with the standard ruby logger to be used by RailsLogstasher
    config.logger = RailsLogstasher::Logger.new(Rails.root.join('log',"#{Rails.env}.log").to_s)

    # Optionally specify a log type tag (default is 'rails')
    config.log_type = 'my_type'

    # Optionally process log entries before they are written to the log
    config.log_entry_processor = Proc.new {|entry| ... do stuff with entry...}

  end
end

Logstash Configuration

RailsLogstasher creates log entries with a default type of "rails", therefore your Logstash configuration file should be as follows:

input {
  file {
    type => "rails"
    path => "/var/www/rails/application-1/log/production.log" # Path to your log file
    format => "json_event"
  }
}

The type can be configured via the application configuration "log_type" setting, like so:

module MyApp
  class Application < Rails::Application

    # Set a different type for the events
    config.log_type = 'my_type'

  end
end

It is possible to configure a Proc to custom handle log entries before they are written to the log file, like so:

module MyApp
  class Application < Rails::Application

    config.log_entry_processor = Proc.new {|entry| entry.fields['my_custom_field'] = 'hello' }

  end
end

You will need to edit the path to point to your application's log file. Because RailsLogstasher creates json serialized Logstash::Event entries there is no need to setup any filters

Known issues

RailsLogstasher currently creates nested JSON. Kibana has pretty good (With a few small UI problems) support for nested JSON but logstash web does not.

Developers

Thoughts, suggestions, opinions and contributions are welcome.

When contributing please make sure to run your tests with warnings enabled and make sure that rails-logstasher creates no warnings. (Warnings from other libraries like capybara etc. are ok)

RUBYOPT=-w rake

rails-logstasher's People

Contributors

rurounijones avatar hobofan avatar drnic avatar ochko avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.