aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG2
-rw-r--r--railties/lib/dispatcher.rb11
-rw-r--r--railties/lib/initializer.rb11
3 files changed, 16 insertions, 8 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index b015d92060..3f77a2f37b 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Changed the default logger from Ruby's own Logger with the clean_logger extensions to ActiveSupport::BufferedLogger for performance reasons [DHH]. (You can change it back with config.logger = Logger.new("/path/to/log", level).)
+
* Added a default 422.html page to be rendered when ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved, or ActionController::InvalidAuthenticityToken is raised [DHH]
* Added --skip-fixture option to script/generate model #6862 [sandofsky]
diff --git a/railties/lib/dispatcher.rb b/railties/lib/dispatcher.rb
index cb1289957e..398acb7e97 100644
--- a/railties/lib/dispatcher.rb
+++ b/railties/lib/dispatcher.rb
@@ -38,13 +38,14 @@ class Dispatcher
controller = ActionController::Routing::Routes.recognize(request)
controller.process(request, response).out(output)
end
- rescue Exception => exception # errors from CGI dispatch
+ rescue Exception => exception # errors from CGI dispatch
failsafe_response(cgi, output, '500 Internal Server Error', exception) do
controller ||= (ApplicationController rescue ActionController::Base)
controller.process_with_exception(request, response, exception).out(output)
end
ensure
- # Do not give a failsafe response here.
+ # Do not give a failsafe response here
+ flush_logger
reset_after_dispatch
end
@@ -165,9 +166,13 @@ class Dispatcher
if defined?(RAILS_DEFAULT_LOGGER) && !RAILS_DEFAULT_LOGGER.nil?
RAILS_DEFAULT_LOGGER
else
- Logger.new($stderr)
+ ActiveSupport::BufferedLogger.new($stderr)
end
end
+
+ def flush_logger
+ RAILS_DEFAULT_LOGGER.flush if defined?(RAILS_DEFAULT_LOGGER) && RAILS_DEFAULT_LOGGER.respond_to?(:flush)
+ end
end
end
diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb
index b9fa9eee01..c2862ee443 100644
--- a/railties/lib/initializer.rb
+++ b/railties/lib/initializer.rb
@@ -240,11 +240,12 @@ module Rails
unless logger = configuration.logger
begin
- logger = Logger.new(configuration.log_path)
- logger.level = Logger.const_get(configuration.log_level.to_s.upcase)
- rescue StandardError
- logger = Logger.new(STDERR)
- logger.level = Logger::WARN
+ logger = ActiveSupport::BufferedLogger.new(configuration.log_path)
+ logger.level = ActiveSupport::BufferedLogger.const_get(configuration.log_level.to_s.upcase)
+ logger.auto_flushing = false if configuration.environment == "production"
+ rescue StandardError =>e
+ logger = ActiveSupport::BufferedLogger.new(STDERR)
+ logger.level = ActiveSupport::BufferedLogger::WARN
logger.warn(
"Rails Error: Unable to access log file. Please ensure that #{configuration.log_path} exists and is chmod 0666. " +
"The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."