aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschneems <richard.schneeman@gmail.com>2016-02-17 10:50:29 -0600
committerschneems <richard.schneeman@gmail.com>2016-02-17 10:50:29 -0600
commit4a836dca6562963c3112ff853017b1174af02251 (patch)
tree6246d4866195ed7370d6c54f100b0892ae7100cf
parent310e4418f4db899dcd07ff24f530ef8862c65f8b (diff)
downloadrails-4a836dca6562963c3112ff853017b1174af02251.tar.gz
rails-4a836dca6562963c3112ff853017b1174af02251.tar.bz2
rails-4a836dca6562963c3112ff853017b1174af02251.zip
Alternative to #23638 log to STDOUT via env var
People who deploy to containers or other places where they might have some sort of a log wrapping service use stdout. With this change new rails apps can be configured to output to STDOUT via setting `RAILS_LOG_TO_STDOUT` to any value. This allows container images or services to set the value for all apps without having to modify configuration for each application. If an app wants to opt out, they can either delete from the env hash, or remove that configuration. cc/ @rafaelfranca
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt4
-rw-r--r--railties/test/application/configuration_test.rb11
2 files changed, 15 insertions, 0 deletions
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
index 82509f5ef5..e14e2c7286 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
@@ -60,6 +60,10 @@ Rails.application.configure do
# require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
+ if ENV["RAILS_LOG_TO_STDOUT"].present?
+ config.logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
+ end
+
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb
index 383f485db5..1c7d1e1f5f 100644
--- a/railties/test/application/configuration_test.rb
+++ b/railties/test/application/configuration_test.rb
@@ -348,6 +348,17 @@ module ApplicationTests
end
end
+ test "In production mode, STDOUT logging is enabled when RAILS_LOG_TO_STDOUT is set" do
+ restore_default_config
+
+ with_rails_env "production" do
+ switch_env "RAILS_LOG_TO_STDOUT", "1" do
+ app 'production'
+ assert ActiveSupport::Logger.logger_outputs_to?(app.config.logger, STDOUT)
+ end
+ end
+ end
+
test "In production mode, config.public_file_server.enabled is disabled when RAILS_SERVE_STATIC_FILES is blank" do
restore_default_config