From 411378efcf3d6bfc33ff1f31dc0ebcc2abdd66f9 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 26 Oct 2012 11:28:51 -0700 Subject: [PATCH] Job worker thread logs to stderr if no logger is provided --- activesupport/lib/active_support/queueing.rb | 3 +-- .../test/queueing/threaded_consumer_test.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/queueing.rb b/activesupport/lib/active_support/queueing.rb index c8ba28021d..0631f4e4a8 100644 --- a/activesupport/lib/active_support/queueing.rb +++ b/activesupport/lib/active_support/queueing.rb @@ -66,7 +66,7 @@ module ActiveSupport class ThreadedQueueConsumer def initialize(queue, options = {}) @queue = queue - @logger = options[:logger] + @logger = options[:logger] || Logger.new($stderr) end def start @@ -96,7 +96,6 @@ module ActiveSupport end def handle_exception(job, exception) - raise exception unless @logger @logger.error "Job Error: #{exception.message}\n#{exception.backtrace.join("\n")}" end end diff --git a/activesupport/test/queueing/threaded_consumer_test.rb b/activesupport/test/queueing/threaded_consumer_test.rb index fc43cb555a..ba3b08efc4 100644 --- a/activesupport/test/queueing/threaded_consumer_test.rb +++ b/activesupport/test/queueing/threaded_consumer_test.rb @@ -71,6 +71,18 @@ class TestThreadConsumer < ActiveSupport::TestCase assert_match 'Job Error: RuntimeError: Error!', @logger.logged(:error).last end + test "logger defaults to stderr" do + begin + $stderr, old_stderr = StringIO.new, $stderr + queue = ActiveSupport::Queue.new + queue.push Job.new { raise "RuntimeError: Error!" } + queue.drain + assert_match 'Job Error', $stderr.string + ensure + $stderr = old_stderr + end + end + test "test overriding exception handling" do @queue.consumer.instance_eval do def handle_exception(job, exception)