Skip to content

Commit

Permalink
Use ActiveSupport::BroadcastLogger (#1089)
Browse files Browse the repository at this point in the history
  • Loading branch information
bensheldon authored Sep 25, 2023
1 parent 05d40f7 commit 379997e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.bundle/
log/*.log
log/
pkg/
vendor/bundle
spec/test_app/log/*.log
Expand Down
16 changes: 9 additions & 7 deletions lib/good_job/log_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,15 @@ def loggers
# each of the loggers in {LogSubscriber.loggers}.
# @return [Logger]
def logger
@_logger ||= begin
logger = Logger.new(StringIO.new)
loggers.each do |each_logger|
logger.extend(ActiveSupport::Logger.broadcast(each_logger))
end
logger
end
@_logger ||= if defined?(ActiveSupport::BroadcastLogger)
ActiveSupport::BroadcastLogger.new(*loggers)
else
logger = Logger.new(StringIO.new)
loggers.each do |each_logger|
logger.extend(ActiveSupport::Logger.broadcast(each_logger))
end
logger
end
end

# Reset {LogSubscriber.logger} and force it to rebuild a new shortcut to
Expand Down
3 changes: 1 addition & 2 deletions sorbet/rbi/todo.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ module ::LATCH; end
module ::MemoryProfiler; end
module ::PERFORMED; end
module ::POLL_COUNT; end
module ::RECEIVED_MESSAGE; end
module ::REFRESH_IF_STALE_CALLED; end
module ::RESULTS; end
module ::RUN_JOBS; end
module ::RecursiveJob; end
Expand All @@ -29,6 +27,7 @@ module ::THREAD_JOBS; end
module ::TestError; end
module ::TestJob; end
module ::TestJob::ExpectedError; end
module ActiveSupport::BroadcastLogger; end
module GoodJob::Job::ERROR_EVENT_INTERRUPTED; end
module GoodJob::Job::ERROR_EVENT_RETRIED; end
module RSpec::Core::Example; end
Expand Down
4 changes: 2 additions & 2 deletions spec/support/database_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
config.use_transactional_fixtures = false

config.before(:suite) do
ApplicationRecord.clear_active_connections!
ApplicationRecord.connection_handler.clear_active_connections!
ApplicationRecord.connection_pool.disconnect
ApplicationRecord.connection_pool.with_connection do |connection|
connection.truncate_tables(*connection.tables)
Expand All @@ -16,7 +16,7 @@
config.around do |example|
example.run

ApplicationRecord.clear_active_connections!
ApplicationRecord.connection_handler.clear_active_connections!
ApplicationRecord.connection_pool.disconnect
ApplicationRecord.connection_pool.with_connection do |connection|
connection.truncate_tables(*connection.tables)
Expand Down

0 comments on commit 379997e

Please sign in to comment.