aboutsummaryrefslogtreecommitdiffstats
path: root/railties/environments
diff options
context:
space:
mode:
Diffstat (limited to 'railties/environments')
-rw-r--r--railties/environments/shared.rb12
-rw-r--r--railties/environments/shared_for_gem.rb12
2 files changed, 22 insertions, 2 deletions
diff --git a/railties/environments/shared.rb b/railties/environments/shared.rb
index cd4d5b205a..c4d52d4b26 100644
--- a/railties/environments/shared.rb
+++ b/railties/environments/shared.rb
@@ -41,7 +41,17 @@ ActiveRecord::Base.establish_connection
# Configure defaults if the included environment did not.
-RAILS_DEFAULT_LOGGER = Logger.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log")
+begin
+ RAILS_DEFAULT_LOGGER = Logger.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log")
+rescue StandardError
+ RAILS_DEFAULT_LOGGER = Logger.new(STDERR)
+ RAILS_DEFAULT_LOGGER.level = Logger::WARN
+ RAILS_DEFAULT_LOGGER.warn(
+ "Rails Error: Unable to access log file. Please ensure that log/#{RAILS_ENV}.log exists and is chmod 0777. " +
+ "The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
+ )
+end
+
[ActiveRecord::Base, ActionController::Base, ActionMailer::Base].each do |klass|
klass.logger ||= RAILS_DEFAULT_LOGGER
end
diff --git a/railties/environments/shared_for_gem.rb b/railties/environments/shared_for_gem.rb
index e82a6344fe..82a5d3295c 100644
--- a/railties/environments/shared_for_gem.rb
+++ b/railties/environments/shared_for_gem.rb
@@ -38,7 +38,17 @@ ActiveRecord::Base.establish_connection
# Configure defaults if the included environment did not.
-RAILS_DEFAULT_LOGGER = Logger.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log")
+begin
+ RAILS_DEFAULT_LOGGER = Logger.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log")
+rescue StandardError
+ RAILS_DEFAULT_LOGGER = Logger.new(STDERR)
+ RAILS_DEFAULT_LOGGER.level = Logger::WARN
+ RAILS_DEFAULT_LOGGER.warn(
+ "Rails Error: Unable to access log file. Please ensure that log/#{RAILS_ENV}.log exists and is chmod 0777. " +
+ "The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
+ )
+end
+
[ActiveRecord::Base, ActionController::Base, ActionMailer::Base].each do |klass|
klass.logger ||= RAILS_DEFAULT_LOGGER
end