Skip to content

Commit

Permalink
Report ActiveSupport::LogSubscriber errors to Rails.error
Browse files Browse the repository at this point in the history
  • Loading branch information
beauraF committed Oct 16, 2024
1 parent f3b154d commit cd8db41
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions activesupport/lib/active_support/log_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ def mode_from(options)
end

def log_exception(name, e)
ActiveSupport.error_reporter.report(e, source: name)

if logger
logger.error "Could not log #{name.inspect} event. #{e.class}: #{e.message} #{e.backtrace}"
end
Expand Down
10 changes: 6 additions & 4 deletions activesupport/test/log_subscriber_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,12 @@ def test_flushes_the_same_logger_just_once
end

def test_logging_does_not_die_on_failures
ActiveSupport::LogSubscriber.attach_to :my_log_subscriber, @log_subscriber
instrument "puke.my_log_subscriber"
instrument "some_event.my_log_subscriber"
wait
assert_error_reported do
ActiveSupport::LogSubscriber.attach_to :my_log_subscriber, @log_subscriber
instrument "puke.my_log_subscriber"
instrument "some_event.my_log_subscriber"
wait
end

assert_equal 1, @logger.logged(:info).size
assert_equal "some_event.my_log_subscriber", @logger.logged(:info).last
Expand Down

0 comments on commit cd8db41

Please sign in to comment.