rails, logs, short blog,

Error in logging! Rails log to STDOUT

Swapnil Gourshete Swapnil Gourshete Follow Mar 27, 2020 · 1 min read
Error in logging! Rails log to STDOUT
Share this

Logs play important role in debugging application. Rails comes with six levels of logging :debug, :info, :warn, :error, :fatal, and :unknown. These logs are generally written to Rails.root/logs/#{environment}.log file of each environment.

The point here is Rails new versions ships with settings to write logs to STDOUT and not environment specific log files. A new environment variable named RAILS_LOG_TO_STDOUT is used to take the decision. In new rails app you will find following code snippet in production.rb

  if ENV['RAILS_LOG_TO_STDOUT'].present?
    logger           = ActiveSupport::Logger.new(STDOUT)
    logger.formatter = config.log_formatter
    config.logger    = ActiveSupport::TaggedLogging.new(logger)

It tells the rails app to write logs to STDOUT and not to Rails.root/log/production.log if ENV[‘RAILS_LOG_TO_STDOUT’] is set to true. The same setting is applied to all environments. This setting can be toggled by simply altering the value set to ENV['RAILS_LOG_TO_STDOUT'].

  • References -

Rails guide - https://guides.rubyonrails.org/debugging_rails_applications.html

Swapnil Gourshete
Written by Swapnil Gourshete Follow
Hi I am Swapnil, a Software Engineer and computer science enthusiastic