Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to output to both log file and STDOUT in new Rails environment?

I've created a new environment file in my Rails 4 app (config/environments/staging.rb). The settings in this file are exactly those found in the default development.rb file created when the app was generated.

When firing up WEBrick in the console using this environment (rails s -e staging or RAILS_ENV=staging rails s), I don't see anything written to STDOUT. I can see the log file for the staging environment being written to, but nothing in STDOUT. I understand I can tail the file, but I was wondering if there was a config setting to handle this. I can also redirect the Rails logger to output everything to STDOUT, but how can I get my custom environment to write to both STDOUT and the log file?

I can replicate this on both OSX and Windows with a new Rails 4 app, and the default environments work as expected.

like image 391
alkalinecoffee Avatar asked Feb 03 '26 13:02

alkalinecoffee


1 Answers

Figured it out. Modify your environment config file to use the Rails::Rack::LogTailer middleware:

# config/environments/staging.rb

Rails.application.configure do
  config.middleware.insert_before(Rails::Rack::Logger, Rails::Rack::LogTailer)
end
like image 145
alkalinecoffee Avatar answered Feb 05 '26 09:02

alkalinecoffee