Loading
Print development logs to STDOUT
What does this MR do and why?
In development, Rails.logger only writes to log/development.log. rails server and rails console add their own console logger, but rake tasks and rails runner don't, so their logs never show up in the terminal or the dev container. That's likely why some rake tasks use puts.
This MR adds config/initializers/log_to_stdout.rb, which broadcasts development logs to STDOUT as well. It uses the same check as rails server, so it skips this when a STDOUT or STDERR logger is already present, and rails server and rails console don't print anything twice.
Only development changes. Production already logs to STDOUT, and test still logs to log/test.log.
Closes #730 (closed)
Screenshots or screen recordings
No UI changes.
Validation steps
- In the dev container, run
bin/rails runner 'Rails.logger.info "hello from runner"'. The message prints in the terminal and is still written tolog/development.log. - Start
bin/rails sand load a page. Each request is logged once in the terminal, not twice. - Start
bin/rails cand runUser.first. The SQL query is logged once.
Edited by Arjun Singh