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

  1. In the dev container, run bin/rails runner 'Rails.logger.info "hello from runner"'. The message prints in the terminal and is still written to log/development.log.
  2. Start bin/rails s and load a page. Each request is logged once in the terminal, not twice.
  3. Start bin/rails c and run User.first. The SQL query is logged once.

/cc @leetickett-gitlab

Edited by Arjun Singh

Merge request reports

Loading
Loading