diff --git a/README.md b/README.md index 947abea..8a438d3 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Or install it yourself as: ## Basic Usage In your api file (somewhere on the top) - + require 'grape_logging' logger.formatter = GrapeLogging::Formatters::Default.new use GrapeLogging::Middleware::RequestLogger, { logger: logger } @@ -50,19 +50,24 @@ You can include logging of other parts of the request / response cycle by includ use GrapeLogging::Middleware::RequestLogger, logger: logger, include: [ GrapeLogging::Loggers::Response.new, - GrapeLogging::Loggers::FilterParameters.new ] + GrapeLogging::Loggers::FilterParameters.new, + GrapeLogging::Loggers::ClientEnv.new ] end +#### FilterParameters 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. +#### ClientEnv +The `FilterParameters` logger will add `ip` and user agent `ua` in your log. + ### Logging to file and STDOUT You can log to file and STDOUT at the same time, you just need to assign new logger - + log_file = File.open('path/to/your/logfile.log', 'a') log_file.sync = true logger Logger.new GrapeLogging::MultiIO.new(STDOUT, log_file) - + ### Logging via Rails instrumentation You can choose to not pass the logger to ```grape_logging``` but instead send logs to Rails instrumentation in order to let Rails and its configured Logger do the log job, for example. @@ -74,16 +79,16 @@ First, config ```grape_logging```, like that: include: [ GrapeLogging::Loggers::Response.new, GrapeLogging::Loggers::FilterParameters.new ] end - + and then add an initializer in your Rails project: - + # config/initializers/instrumentation.rb - + # Subscribe to grape request and log with Rails.logger ActiveSupport::Notifications.subscribe('grape_key') do |name, starts, ends, notification_id, payload| Rails.logger.info payload end - + The idea come from here: https://gist.github.com/teamon/e8ae16ffb0cb447e5b49 ### Logging exceptions