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
endRails
module MyApp
class Application < Rails::Application
# ...
config.middleware.use "Rack::KeyValueLogger"
end
endConfiguration
A number of configuration options are supported when adding
Rack::KeyValueLogger to the middleware stack.
-
:log_failure_response_bodies-trueorfalse. Logs the entire response body to theresponse_bodykey on 40x responses. Defaults tofalse. -
:ignore_paths- A regular expression of paths we should not log. -
:logger- ALoggerinstance. Defaults toLogger($stdout). -
:user_id- A string key at which the current user's id is stored inenv["rack.session"]. Defaults to "user_id".