rails logger color
# Step 1: Require the 'colorize' gem in your Rails application.
gem 'colorize', '~> 0.8.1'
# Step 2: Install the gem by running the following command in your terminal.
bundle install
# Step 3: Open the Rails application's configuration file (e.g., config/application.rb).
# Step 4: Require the 'colorize' gem in the configuration file.
require 'colorize'
# Step 5: Configure the Rails logger to use colorized output.
config.logger = ActiveSupport::Logger.new(STDOUT)
config.logger.formatter = proc do |severity, datetime, progname, msg|
case severity
when "DEBUG"
msg.to_s.green
when "INFO"
msg.to_s.blue
when "WARN"
msg.to_s.yellow
when "ERROR"
msg.to_s.red
when "FATAL"
msg.to_s.red.bold
else
msg.to_s
end
end
Now your Rails logger will display log messages in different colors based on their severity levels.