diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-19 13:29:39 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-19 13:29:39 +0000 |
commit | b586c7a97ab7b2b7bf9fde4710e10ca3343a2e3f (patch) | |
tree | 891d58cb706c9e3e9254685f205cefcf24785904 | |
parent | 3b56b85906d4b1534a73b63b80244b5e1e06f3b2 (diff) | |
download | rails-b586c7a97ab7b2b7bf9fde4710e10ca3343a2e3f.tar.gz rails-b586c7a97ab7b2b7bf9fde4710e10ca3343a2e3f.tar.bz2 rails-b586c7a97ab7b2b7bf9fde4710e10ca3343a2e3f.zip |
Added graceful handling of an inaccessible log file by redirecting output to STDERR with a warning #330 [rainmkr]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@223 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | railties/CHANGELOG | 4 | ||||
-rw-r--r-- | railties/environments/shared.rb | 12 | ||||
-rw-r--r-- | railties/environments/shared_for_gem.rb | 12 |
3 files changed, 25 insertions, 3 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 043b9edfa3..003ac065ac 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,8 +1,10 @@ *SVN* +* Added graceful handling of an inaccessible log file by redirecting output to STDERR with a warning #330 [rainmkr] + * Added support for a -h/--help parameter in the generator #331 [Ulysses] -* File.expand_path in config/environment.rb would fail when dealing with symlinked public directories [mjobin]. +* File.expand_path in config/environment.rb would fail when dealing with symlinked public directories [mjobin] *0.9.1* 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 |