From 558030b6dc9d1e6c35795877e5afaa7c01b9f872 Mon Sep 17 00:00:00 2001 From: Ryan Buckley Date: Sat, 12 Dec 2015 01:04:19 -0800 Subject: [PATCH] reorganize the readme --- README.md | 60 +++++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 516ab1c..4aa32af 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,36 @@ end Server requests will be logged to STDOUT by default. -#### Rails +## Custom setup +Customize the logging by passing the `logger` option. Example using a CustomLogger and parameter sanitization: +```ruby +use Grape::Middleware::Logger, { + logger: CustomLogger.new, + filter: CustomFilter.new +} +``` +The `logger` option can be any object that responds to `.info(msg)` + +The `filter` option can be any object that responds to `.filter(params_hash)` + +## Example output +Get +``` +Started GET "/v1/reports/101" at 2015-12-11 15:40:51 -0800 +Processing by ReportsAPI#reports/:id + Parameters: {"id"=>"101"} +Completed 200 in 6.29ms +``` +Error +``` +Started POST "/v1/reports" at 2015-12-11 15:42:33 -0800 +Processing by ReportsAPI#reports + Parameters: {"name"=>"foo", "password"=>"[FILTERED]"} + Error: {:error=>"undefined something something bad", :detail=>"Whoops"} +Completed 422 in 6.29ms +``` + +## Using Rails? `Rails.logger` and `Rails.application.config.filter_parameters` will be used automatically as the default logger and param filterer, respectively. @@ -51,35 +80,6 @@ class SelectiveLogger end ``` -#### Custom setup -Customize the logging by passing the `logger` option. Example using a CustomLogger and parameter sanitization: -```ruby -use Grape::Middleware::Logger, { - logger: CustomLogger.new, - filter: ActionDispatch::Http::ParameterFilter.new(Rails.application.config.filter_parameters) -} -``` -The `logger` option can be any object that responds to `.info(msg)` - -The `filter` option can be any object that responds to `.filter(params_hash)` - -## Example output -Get -``` -Started GET "/v1/reports/101" at 2015-12-11 15:40:51 -0800 -Processing by ReportsAPI#reports/:id - Parameters: {"id"=>"101"} -Completed 200 in 6.29ms -``` -Error -``` -Started POST "/v1/reports" at 2015-12-11 15:42:33 -0800 -Processing by ReportsAPI#reports - Parameters: {"name"=>"foo", "password"=>"[FILTERED]"} - Error: {:error=>"undefined something something bad", :detail=>"Whoops"} -Completed 422 in 6.29ms -``` - ## Rack If you're using the `rackup` command to run your server in development, pass the `-q` flag to silence the default rack logger.