Skip to content

Commit

Permalink
Honour RAILS_LOG_TO_STDOUT in config/environments/production.rb
Browse files Browse the repository at this point in the history
12-factor apps should log to STDOUT, so that the platform can capture
the logs in a standard way.

This is already the case for newly created applications:
rails/rails@e9b96f0

(software-o-o was created prior to this change).

With this change, Rails will still log by default to
log/production.log, but if the platform sets RAILS_LOG_TO_STDOUT, it
will be able to capture the logs.

In the same way, if the systemd .service file sets

```
Environment="RAILS_LOG_TO_STDOUT=1"
```

Then you will be able to control/see the logs with journalctl.
  • Loading branch information
dmacvicar committed Feb 3, 2018
1 parent b7440c7 commit 3521ce3
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@
# Rake tasks automatically ignore this option for performance.
config.eager_load = true

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

0 comments on commit 3521ce3

Please sign in to comment.