No commit activity in last 3 years
No release in over 3 years
Structured, key-value logging for your rack apps. Inspired by lograge.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

Build Status

What

Structured, key-value logging for your rack apps. Inspired by lograge.

Why?

Application logs are an incredibly rich source of information. But digging out the information can be extremely painful if your logs are not structured in an easily parsable manner.

Rack::KeyValueLogger logs key-value pairs, where the key and value are separated by a "=" character. Pairs are separated by pipe ("|") characters. Here's an example of what a log line looks like:

ts=2013-04-26T01:14:36Z|method=GET|url=/homepage|params=page=2|user_id=123|scheme=http|user_agent=curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5|remote_ip=127.0.0.1|http_version=HTTP/1.1|requested_content_type=text/html|log_source=key_value_logger|status=200|content-length=111|content_type=text/html|runtime=21.553

Get Started

gem 'rack-key_value_logger'

Sinatra

class MyApp < Sinatra::Base
  use Rack::KeyValueLogger
end

Rails

module MyApp
  class Application < Rails::Application
    # ...
    config.middleware.use "Rack::KeyValueLogger"
  end
end

Configuration

A number of configuration options are supported when adding Rack::KeyValueLogger to the middleware stack.

  • :log_failure_response_bodies - true or false. Logs the entire response body to the response_body key on 40x responses. Defaults to false.
  • :ignore_paths - A regular expression of paths we should not log.
  • :logger - A Logger instance. Defaults to Logger($stdout).
  • :user_id - A string key at which the current user's id is stored in env["rack.session"]. Defaults to "user_id".