From 126a4b2547a64913543b62ed4e864099b38618aa Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Thu, 24 Feb 2011 13:11:57 -0800 Subject: [PATCH] LOG MORE, on resque job errors --- lib/resque_job_logging.rb | 12 +++++++++++- spec/lib/resque_job_logging_spec.rb | 7 +++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/resque_job_logging.rb b/lib/resque_job_logging.rb index 91b980046..26c8c6ff7 100644 --- a/lib/resque_job_logging.rb +++ b/lib/resque_job_logging.rb @@ -11,7 +11,11 @@ module ResqueJobLogging end }*1000 if error - log_string += "status=error error=\"#{error}\" " + log_string += "status=error " + log_string << "error_class=#{error.class} error_message='#{error.message}' " + log_string << "orig_error_message='#{error.original_error.message}'" if error.respond_to?(:original_error) + log_string << "annotated_source='#{error.annoted_source_code.to_s}' " if error.respond_to?(:annoted_source_code) + log_string << "app_backtrace='#{application_trace(error).join(";")}' " else log_string += "status=complete " end @@ -21,4 +25,10 @@ module ResqueJobLogging Rails.logger.info(log_string) raise error if error end + + def application_trace(error) #copied from ActionDispatch::ShowExceptions + defined?(Rails) && Rails.respond_to?(:backtrace_cleaner) ? + Rails.backtrace_cleaner.clean(error.backtrace, :silent) : + error.backtrace + end end diff --git a/spec/lib/resque_job_logging_spec.rb b/spec/lib/resque_job_logging_spec.rb index 1bdc9b045..a3a60d454 100644 --- a/spec/lib/resque_job_logging_spec.rb +++ b/spec/lib/resque_job_logging_spec.rb @@ -23,4 +23,11 @@ describe ResqueJobLogging do ## pass a nil block, so we can test the .info() output ResqueJobLoggingDummy.around_perform_log_job("foo", "bar", "baz") {} end + it 'logs stack traces on failure' do + Rails.logger.should_receive(:info).with(/app_backtrace=/) + proc { + ResqueJobLoggingDummy.around_perform_log_job("stuff"){raise "GRAAAAAAAAAGH"} + }.should raise_error + + end end