The project is in a healthy, maintained state
Rails and ActiveSupport request logging for Grape APIs, with request context and ActiveRecord timings.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

Runtime

>= 7.0, < 9.0
>= 7.0, < 9.0
>= 1.6, < 5.0
 Project Readme

grape_rails_logger

Gem Version Test Status codecov

Rails-compatible structured logging for Grape APIs with ActiveRecord timing, parameter filtering, and exception tracking.

Installation

Add to your Gemfile:

gem "grape_rails_logger"

Run bundle install or gem install grape_rails_logger.

Usage

In a Rails app, adding the gem is enough. The Railtie patches Grape::Endpoint#build_stack, subscribes to grape.request, and writes structured data through Rails.logger. Any Rails logger works; pair with activesupport-json_logging for JSON lines.

What gets logged

Each request logs structured data with:

  • Request metadata: method, path, status, duration, host, remote_addr, request_id
  • Route information: controller, action, source_location (file:line)
  • Performance metrics: duration (ms), db (ActiveRecord query time in ms), db_calls (SQL query count)
  • Parameters: params (filtered with Rails filter_parameters)
  • Exceptions: exception object with class, message, and backtrace (non-production only)

Configuration

Configure parameter filtering in config/initializers/filter_parameter_logging.rb:

Rails.application.config.filter_parameters += [
  :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn
]

When Rails ParameterFilter is not available, the gem falls back to manual key filtering with patterns aligned to those defaults (passw, secret, token, _key, crypt, salt, certificate, otp, ssn, authorization).

Debug tracing

Optional DebugTracer middleware traces requests when the debug gem is present and TRACE is set:

class API < Grape::API
  use GrapeRailsLogger::DebugTracer
end

Enable tracing: TRACE=1 rails server. Without the debug gem, the middleware does not start a tracer.

Compatibility

  • Rails 7.0, 7.1, 7.2, 8.0+
  • Grape >= 1.6, < 5.0
  • Ruby >= 3.4

In Rails 7.1+, request state uses ActiveSupport::IsolatedExecutionState. On Rails 7.0, it uses Thread.current.

Development

bundle install
bundle exec appraisal generate
bundle exec polyrun parallel-rspec --workers 5 --merge-failures
bin/appraisals
bundle exec standardrb --fix

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/amkisko/grape_rails_logger.rb

Contribution policy:

  • New features are not necessarily added to the gem
  • Pull request should have test coverage for affected parts
  • Pull request should have changelog entry

Review policy:

  • It might take up to 2 calendar weeks to review and merge critical fixes
  • It might take up to 6 calendar months to review and merge pull request
  • It might take up to 1 calendar year to review an issue

Publishing

rm grape_rails_logger-*.gem
gem build grape_rails_logger.gemspec
gem push grape_rails_logger-*.gem

Or use the release script:

usr/bin/release.rb

Links

License

The gem is available as open source under the terms of the MIT License.

Sponsors

Sponsored by Kisko Labs.

Sponsored by Kisko Labs