Merge pull request #48772 from mhib/tagged-logger-proxy-block-support

Prevent inspecting transmit data if not necessary
This commit is contained in:
Matthew Draper 2023-07-21 16:15:08 +09:30 committed by GitHub
commit ea9b647806
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 7 deletions

View File

@ -212,9 +212,11 @@ module ActionCable
# Transmit a hash of data to the subscriber. The hash will automatically be wrapped in a JSON envelope with
# the proper channel identifier marked as the recipient.
def transmit(data, via: nil) # :doc:
status = "#{self.class.name} transmitting #{data.inspect.truncate(300)}"
status += " (via #{via})" if via
logger.debug(status)
logger.debug do
status = "#{self.class.name} transmitting #{data.inspect.truncate(300)}"
status += " (via #{via})" if via
status
end
payload = { channel_class: self.class.name, data: data, via: via }
ActiveSupport::Notifications.instrument("transmit.action_cable", payload) do

View File

@ -30,14 +30,14 @@ module ActionCable
end
%i( debug info warn error fatal unknown ).each do |severity|
define_method(severity) do |message|
log severity, message
define_method(severity) do |message = nil, &block|
log severity, message, &block
end
end
private
def log(type, message) # :doc:
tag(@logger) { @logger.send type, message }
def log(type, message, &block) # :doc:
tag(@logger) { @logger.send type, message, &block }
end
end
end