From a6de6f508c6566af098999ca70f93ee8023bc9a5 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Mon, 17 Nov 2014 04:17:23 -0800 Subject: [PATCH] Deprecate different default for `log_level` in production This is a more conservative approach to 2602a49. Also changed the comment to be more inline with everything else in the file (describing what the config value is doing and why). People should just read the docs for alternatives. --- railties/lib/rails/application/bootstrap.rb | 13 +++++++++++++ railties/lib/rails/application/configuration.rb | 13 +++++++++++-- .../templates/config/environments/production.rb.tt | 3 ++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb index 0f4d932749..92ecc29a5f 100644 --- a/railties/lib/rails/application/bootstrap.rb +++ b/railties/lib/rails/application/bootstrap.rb @@ -1,5 +1,6 @@ require "active_support/notifications" require "active_support/dependencies" +require "active_support/deprecation" require "active_support/descendants_tracker" module Rails @@ -54,6 +55,18 @@ module Bootstrap logger end + if Rails.env.production? && !config.has_explicit_log_level? + ActiveSupport::Deprecation.warn \ + "You did not specify a `log_level` in `production.rb`. Currently, " \ + "the default value for `log_leve` is `:info` for the production " \ + "environment and `:debug` in all other environments. In Rails 5 " \ + "the default value will be unified to `:debug` across all " \ + "environments. To preserve the current setting, add the following " \ + "line to your `production.rb`:\n" \ + "\n" \ + " config.log_level = :info\n\n" + end + Rails.logger.level = ActiveSupport::Logger.const_get(config.log_level.to_s.upcase) end diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 8a5bce64a0..268ef2c7aa 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -15,7 +15,6 @@ class Configuration < ::Rails::Engine::Configuration :time_zone, :reload_classes_only_on_change, :beginning_of_week, :filter_redirect, :x - attr_writer :log_level attr_reader :encoding def initialize(*) @@ -34,6 +33,7 @@ def initialize(*) @session_options = {} @time_zone = "UTC" @beginning_of_week = :monday + @has_explicit_log_level = false @log_level = nil @middleware = app_middleware @generators = app_generators @@ -117,8 +117,17 @@ def database_configuration raise e, "Cannot load `Rails.application.database_configuration`:\n#{e.message}", e.backtrace end + def has_explicit_log_level? # :nodoc: + @has_explicit_log_level + end + + def log_level=(level) + @has_explicit_log_level = !!(level) + @log_level = level + end + def log_level - @log_level ||= Rails.env.production? ? :info : :debug + @log_level ||= (Rails.env.production? ? :info : :debug) end def colorize_logging 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 aa7b93f0a1..91dea5858f 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 @@ -45,7 +45,8 @@ Rails.application.configure do # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true - # Set to :info to decrease the log volume. + # Use the lowest log_level to ensure availability of diagnostic information + # when problems arise. config.log_level = :debug # Prepend all log lines with the following tags.