DEV Community

nishikawa1031
nishikawa1031

Posted on

2

A new gem that eliminates the hassle of launching the Rails app every time just to check the logs.

Introduction

During Rails development, I found that the wait time to start the Rails server was surprisingly stressful. On the other hand, the logs output to development.log were often overwhelming...

So, I created a gem that divides and outputs the logs by each controller's action in separate folders, allowing for easier management of logs during each request.

custom_log_space | RubyGems.org | Community Gem Hosting Service

Installation

Add gem 'custom_log_space' to your Gemfile as shown below and run bundle install.

group :development do
  + gem 'custom_log_space'
end
Enter fullscreen mode Exit fullscreen mode

Usage

Launch your Rails app locally. When you access a page, logs will be generated in the log/custom_log_space directory, following the naming convention below.

log/custom_log_space/#{controller_name}/#{action_name}/#{date}/#{time}.log
Enter fullscreen mode Exit fullscreen mode

Example:

user log % tree
.
├── custom_log_space
│   └── articles_controller
│       ├── index
│       │   ├── 2023-09-19
│       │   │   ├── 09:13.log
│       │   │   └── 20:00.log
│       │   └── saved
│       └── show
│           ├── 2023-09-18
│           │   ├── 21:29.log
│           │   └── 22:02.log
│           ├── 2023-09-19
│           │   └── 20:00.log
│           └── saved
└── development.log
Enter fullscreen mode Exit fullscreen mode

Log Retention Policy

  • The maximum number of #{date} folders retained is two, and for #{time}.log, up to 10 files. Once these limits are exceeded, older files will be deleted sequentially.
  • Please move important logs to the saved directory. log/custom_log_space/#{controller_name}/#{action_name}/saved/

Caveats

  • If a single request triggers multiple controller actions, logs will be organized into separate folders for each action. Therefore, caution is needed when tracing the logs.
  • However, even after introducing this gem, the output to the existing development.log remains unchanged. You can continue to refer to it as needed.

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs