mirror of
https://github.com/samsonjs/grape_logging.git
synced 2026-03-25 08:55:47 +00:00
updating README with usage examples
This commit is contained in:
parent
e5cff12673
commit
def34f7b8d
1 changed files with 25 additions and 5 deletions
30
README.md
30
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue