The project is in a healthy, maintained state
A command-line tool for extracting, formatting, and analyzing Rails request logs to identify performance bottlenecks and gain insights.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies
 Project Readme

select_rails_log

select_rails_log is a tool for parsing Rails log files and extracting request logs based on a variety of criteria. These criteria include controller/action names, request date and time, response duration, and more.

The tool allows you to output the extracted logs in various formats and provides summary metrics such as percentiles and histograms. It is particularly useful during development for identifying application bottlenecks or conducting small-scale benchmarking.

Features

Extraction Criteria

You can specify the following criteria to extract request logs:

  • Request-ID
  • Controller name and action name
  • HTTP method and status code
  • Date and time range of the request
  • Response time range
  • String matching within logs

Output Formats

Extracted logs can be output in the following formats:

  • Text
  • JSON, JSONL
  • TSV
  • Raw log

Summarization Options

The tool supports the following summarization features:

  • Percentiles by controller and action
  • Box plots by controller and action
  • Histograms for the overall extraction results

Installation

Install the gem by executing:

gem install select_rails_log

Usage

select_rails_log can process logs that include timestamps and Request-IDs.

To enable this, first configure the appropriate settings file, such as config/environments/development.rb, as follows:

config.log_tags = [:request_id]
config.log_formatter = ::Logger::Formatter.new

Sample session

Here are some usage examples.

To output a box plot for an overview, use the following command:

select_rails_log log/development.log --boxplot

The result will be output as follows:

boxplot

Next, let’s examine the response time distribution for ActiveStorage::Representations::RedirectController#show, which had significant variance:

select_rails_log log/development.log -A 'ActiveStorage::Representations::RedirectController#show' --histgram

histgram

Finally, let’s take a closer look at requests that took particularly long, specifically those over 400ms:

select_rails_log log/development.log -A 'ActiveStorage::Representations::RedirectController#show' -D 400..

text

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test-unit to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/arika/select_rails_log. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

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

Code of Conduct

Everyone interacting in the SelectRailsLog project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.