diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2012-10-26 16:18:39 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2012-10-26 16:18:52 -0700 |
commit | bf2009f995dd8cf5cbe43908de18580d0e94e2e1 (patch) | |
tree | f6a4a3669a46f8523845cefa8f008fc8506b3fd6 | |
parent | 26f52b2ac1f8d6208bd017e6c0241e33147f5284 (diff) | |
download | rails-bf2009f995dd8cf5cbe43908de18580d0e94e2e1.tar.gz rails-bf2009f995dd8cf5cbe43908de18580d0e94e2e1.tar.bz2 rails-bf2009f995dd8cf5cbe43908de18580d0e94e2e1.zip |
Job consumer logs to Rails.logger by default
-rw-r--r-- | activesupport/lib/active_support/queueing.rb | 7 | ||||
-rw-r--r-- | railties/lib/rails/application/finisher.rb | 1 | ||||
-rw-r--r-- | railties/test/application/queue_test.rb | 1 |
3 files changed, 7 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/queueing.rb b/activesupport/lib/active_support/queueing.rb index 6de038ee0e..064f009f13 100644 --- a/activesupport/lib/active_support/queueing.rb +++ b/activesupport/lib/active_support/queueing.rb @@ -64,9 +64,12 @@ module ActiveSupport # queue and joins the thread, which will ensure that all jobs # are executed before the process finally dies. class ThreadedQueueConsumer + attr_accessor :logger + def initialize(queue, options = {}) @queue = queue - @logger = options[:logger] || Logger.new($stderr) + @logger = options[:logger] + @fallback_logger = Logger.new($stderr) end def start @@ -96,7 +99,7 @@ module ActiveSupport end def handle_exception(job, exception) - @logger.error "Job Error: #{job.inspect}\n#{exception.message}\n#{exception.backtrace.join("\n")}" + (logger || @fallback_logger).error "Job Error: #{job.inspect}\n#{exception.message}\n#{exception.backtrace.join("\n")}" end end end diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index c520f7af9d..2d87b8594a 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -99,6 +99,7 @@ module Rails initializer :activate_queue_consumer do |app| if config.queue.class == ActiveSupport::Queue app.queue_consumer = config.queue_consumer || config.queue.consumer + app.queue_consumer.logger ||= Rails.logger if app.queue_consumer.respond_to?(:logger=) app.queue_consumer.start at_exit { app.queue_consumer.shutdown } end diff --git a/railties/test/application/queue_test.rb b/railties/test/application/queue_test.rb index b0b3cf18e9..219a35da35 100644 --- a/railties/test/application/queue_test.rb +++ b/railties/test/application/queue_test.rb @@ -78,6 +78,7 @@ module ApplicationTests assert_nil Rails.application.config.queue_consumer assert_kind_of ActiveSupport::ThreadedQueueConsumer, Rails.application.queue_consumer + assert_equal Rails.logger, Rails.application.queue_consumer.logger end test "attempting to marshal a queue will raise an exception" do |