From def34f7b8d6b722dc43a9e4b559facb5782d81e8 Mon Sep 17 00:00:00 2001 From: Duncan Williams Date: Mon, 13 Jul 2015 16:38:35 +0100 Subject: [PATCH] updating README with usage examples --- README.md | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6925a8f..4cac959 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Add this line to your application's Gemfile: And then execute: - $ bundle + $ bundle install Or install it yourself as: @@ -18,11 +18,11 @@ Or install it yourself as: ## Basic Usage -In your api file (somewhere on the top) - - logger.formatter = GrapeLogging::Formatters::Default.new - use GrapeLogging::Middleware::RequestLogger, { logger: logger } +Include the middleware in your api + class MyAPI < Grape::API + use GrapeLogging::Middleware::RequestLogger, logger: logger + end ## 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 ;) +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 You can to file and STDOUT at the same time, you just need to assign new logger