updating README with usage examples

This commit is contained in:
Duncan Williams 2015-07-13 16:38:35 +01:00
parent 7ba9b5b83a
commit 2c208bd5c5

View file

@ -10,7 +10,7 @@ Add this line to your application's Gemfile:
And then execute: And then execute:
$ bundle $ bundle install
Or install it yourself as: Or install it yourself as:
@ -18,11 +18,11 @@ Or install it yourself as:
## Basic Usage ## Basic Usage
In your api file (somewhere on the top) Include the middleware in your api
logger.formatter = GrapeLogging::Formatters::Default.new
use GrapeLogging::Middleware::RequestLogger, { logger: logger }
class MyAPI < Grape::API
use GrapeLogging::Middleware::RequestLogger, logger: logger
end
## Features ## Features
@ -34,6 +34,26 @@ With the default configuration you will get nice log message
If you prefer some other format I strongly encourage you to do pull request with new formatter class ;) If you prefer some other format I strongly encourage you to do pull request with new formatter class ;)
You can change the formatter like so
class MyAPI < Grape::API
use GrapeLogging::Middleware::RequestLogger, logger: logger, format: MyFormatter.new
end
### Customising What Is Logged
You can include logging of other parts of the request / response cycle by including subclasses of `GrapeLogging::Loggers::Base`
class MyAPI < Grape::API
use GrapeLogging::Middleware::RequestLogger,
logger: logger,
include: [ GrapeLogging::Loggers::Response.new,
GrapeLogging::Loggers::DatabaseTime.new,
GrapeLogging::Loggers::FilterParameters.new ]
end
The `FilterParameters` logger will filter out sensitive parameters from your logs. If mounted inside rails, will use the `Rails.application.config.filter_parameters` by default. Otherwise, you must specify a list of keys to filter out.
### Logging to file and STDOUT ### Logging to file and STDOUT
You can to file and STDOUT at the same time, you just need to assign new logger You can to file and STDOUT at the same time, you just need to assign new logger