diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2015-06-19 23:06:36 +0200 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2015-06-19 23:06:36 +0200 |
commit | 3759071420d7bd795f38cf26f0bb381c582009b1 (patch) | |
tree | 1c77f14bad0446c4d9b37a21cdc93250d5d878d9 /lib | |
parent | 4ebd8cecb85ffcd2292c1a7d0013a2725448f365 (diff) | |
download | rails-3759071420d7bd795f38cf26f0bb381c582009b1.tar.gz rails-3759071420d7bd795f38cf26f0bb381c582009b1.tar.bz2 rails-3759071420d7bd795f38cf26f0bb381c582009b1.zip |
Improve logging
Diffstat (limited to 'lib')
-rw-r--r-- | lib/action_cable/channel/base.rb | 35 | ||||
-rw-r--r-- | lib/action_cable/channel/redis.rb | 8 | ||||
-rw-r--r-- | lib/action_cable/connection/base.rb | 1 |
3 files changed, 26 insertions, 18 deletions
diff --git a/lib/action_cable/channel/base.rb b/lib/action_cable/channel/base.rb index 1a69d50885..6060ccf681 100644 --- a/lib/action_cable/channel/base.rb +++ b/lib/action_cable/channel/base.rb @@ -7,8 +7,6 @@ module ActionCable on_subscribe :start_periodic_timers on_unsubscribe :stop_periodic_timers - on_unsubscribe :disconnect - attr_reader :params, :connection delegate :logger, to: :connection @@ -30,10 +28,7 @@ module ActionCable @_active_periodic_timers = [] @params = params - connect - run_subscribe_callbacks - - logger.info "#{self.class.name} connected" + perform_connection end def perform_action(data) @@ -41,10 +36,10 @@ module ActionCable action = extract_action(data) if performable_action?(action) - logger.info "Processing #{compose_signature(action, data)}" + logger.info channel_name + compose_signature(action, data) public_send action, data else - logger.error "Failed to process #{compose_signature(action, data)}" + logger.error "#{channel_name} failed to process #{compose_signature(action, data)}" end else unauthorized @@ -52,8 +47,15 @@ module ActionCable end def perform_disconnection + disconnect run_unsubscribe_callbacks - logger.info "#{self.class.name} disconnected" + logger.info "#{channel_name} disconnected" + end + + def perform_connection + logger.info "#{channel_name} connecting" + connect + run_subscribe_callbacks end protected @@ -63,9 +65,10 @@ module ActionCable end def unauthorized - logger.error "Unauthorized access to #{self.class.name}" + logger.error "#{channel_name}: Unauthorized access" end + def connect # Override in subclasses end @@ -74,15 +77,21 @@ module ActionCable # Override in subclasses end + def broadcast(data) if authorized? - logger.info "Broadcasting: #{data.inspect}" + logger.info "#{channel_name} broadcasting #{data.inspect}" connection.broadcast({ identifier: @channel_identifier, message: data }.to_json) else unauthorized end end + + def channel_name + self.class.name + end + private def extract_action(data) (data['action'].presence || :receive).to_sym @@ -93,9 +102,9 @@ module ActionCable end def compose_signature(action, data) - "#{self.class.name}##{action}".tap do |signature| + "##{action}".tap do |signature| if (arguments = data.except('action')).any? - signature << ": #{arguments.inspect}" + signature << "(#{arguments.inspect})" end end end diff --git a/lib/action_cable/channel/redis.rb b/lib/action_cable/channel/redis.rb index 6d114eee7e..b5fc812919 100644 --- a/lib/action_cable/channel/redis.rb +++ b/lib/action_cable/channel/redis.rb @@ -13,15 +13,15 @@ module ActionCable @_redis_channels ||= [] @_redis_channels << [ redis_channel, callback ] - logger.info "Subscribing to the redis channel: #{redis_channel}" pubsub.subscribe(redis_channel, &callback) + logger.info "#{channel_name} subscribed to incoming actions from #{redis_channel}" end def unsubscribe_from_all_channels if @_redis_channels - @_redis_channels.each do |channel, callback| - logger.info "Unsubscribing from the redis channel: #{channel}" - pubsub.unsubscribe_proc(channel, callback) + @_redis_channels.each do |redis_channel, callback| + pubsub.unsubscribe_proc(redis_channel, callback) + logger.info "#{channel_name} unsubscribed from incoming actions #{redis_channel}" end end end diff --git a/lib/action_cable/connection/base.rb b/lib/action_cable/connection/base.rb index c1efca9484..cb9267e2f5 100644 --- a/lib/action_cable/connection/base.rb +++ b/lib/action_cable/connection/base.rb @@ -136,7 +136,6 @@ module ActionCable subscription_klass = server.registered_channels.detect { |channel_klass| channel_klass.find_name == id_options[:channel] } if subscription_klass - logger.info "Subscribing to channel: #{id_key}" @subscriptions[id_key] = subscription_klass.new(self, id_key, id_options) else logger.error "Subscription class not found (#{data.inspect})" |