Skip to content

Override Rack's built-in request logging mechanism to provide logstash-friendly JSON

License

Notifications You must be signed in to change notification settings

LeeXGreen/rack-requestash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rack::Requestash

Simple Rack "middleware" for generating logstash friendly request access logs for any Rack-based application.

Installation

Add this line to your application's Gemfile:

gem 'rack-requestash'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rack-requestash

Usage

Rack::Requestash will monkey-patch the Rack::CommonLogger class which provides Apache-style access logs. In order to enable in in your application, try something like:

require 'rack/requestash'

class MyServer < Sinatra::Base
  use Rack::Requestash::AccessLogger

  get '/' do
   'Yahtzee!'
  end
end

You will then get nice, JSON formatted logs:

{"length":"2818","code":"200","version":"HTTP/1.1","method":"GET","duration":0.280802331,"query":"","path":"/","ip":"127.0.0.1","user":null,"timestamp":"2013-08-15T05:49:00Z"}
{"length":0,"code":"304","version":"HTTP/1.1","method":"GET","duration":0.035969114,"query":"","path":"/javascripts/vendor.js","ip":"127.0.0.1","user":null,"timestamp":"2013-08-15T05:49:00Z"}
{"length":0,"code":"304","version":"HTTP/1.1","method":"GET","duration":0.069988507,"query":"","path":"/javascripts/i18n/en.js","ip":"127.0.0.1","user":null,"timestamp":"2013-08-15T05:49:00Z"}

Contributing

  1. Fork it
  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 new Pull Request

About

Override Rack's built-in request logging mechanism to provide logstash-friendly JSON

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages