aboutsummaryrefslogtreecommitdiffstats
path: root/lib/action_cable/connection/base.rb
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2015-04-07 16:32:45 -0500
committerPratik Naik <pratiknaik@gmail.com>2015-04-07 16:32:45 -0500
commitde8390959664eaccf3453d69be5fa8ce09f97297 (patch)
treeb9bc80f3dca2782c0974dea9546db16a34285bdd /lib/action_cable/connection/base.rb
parent265f1f1ebae2422df8ee9fe66184d6cd20c73494 (diff)
downloadrails-de8390959664eaccf3453d69be5fa8ce09f97297.tar.gz
rails-de8390959664eaccf3453d69be5fa8ce09f97297.tar.bz2
rails-de8390959664eaccf3453d69be5fa8ce09f97297.zip
Log request start and finish
Diffstat (limited to 'lib/action_cable/connection/base.rb')
-rw-r--r--lib/action_cable/connection/base.rb34
1 files changed, 32 insertions, 2 deletions
diff --git a/lib/action_cable/connection/base.rb b/lib/action_cable/connection/base.rb
index 4ad1e7d065..2e62c78bee 100644
--- a/lib/action_cable/connection/base.rb
+++ b/lib/action_cable/connection/base.rb
@@ -16,7 +16,9 @@ module ActionCable
end
def process
- if Faye::WebSocket.websocket?(@env)
+ logger.info "[ActionCable] #{started_request_message}"
+
+ if websocket?
@subscriptions = {}
@websocket = Faye::WebSocket.new(@env)
@@ -40,6 +42,8 @@ module ActionCable
end
@websocket.on(:close) do |event|
+ logger.info "[ActionCable] #{finished_request_message}"
+
worker_pool.async.invoke(self, :cleanup_subscriptions)
worker_pool.async.invoke(self, :cleanup_internal_redis_subscriptions)
worker_pool.async.invoke(self, :disconnect) if respond_to?(:disconnect)
@@ -75,7 +79,7 @@ module ActionCable
end
def broadcast(data)
- logger.info "Sending data: #{data}"
+ logger.info "[ActionCable] Sending data: #{data}"
@websocket.send data
end
@@ -133,6 +137,7 @@ module ActionCable
end
def invalid_request
+ logger.info "[ActionCable] #{finished_request_message}"
[404, {'Content-Type' => 'text/plain'}, ['Page not found']]
end
@@ -140,6 +145,31 @@ module ActionCable
@websocket && @websocket.ready_state == Faye::WebSocket::API::OPEN
end
+ def request
+ @request ||= ActionDispatch::Request.new(env)
+ end
+
+ def websocket?
+ @is_websocket ||= Faye::WebSocket.websocket?(@env)
+ end
+
+ def started_request_message
+ 'Started %s "%s"%s for %s at %s' % [
+ request.request_method,
+ request.filtered_path,
+ websocket? ? ' [Websocket]' : '',
+ request.ip,
+ Time.now.to_default_s ]
+ end
+
+ def finished_request_message
+ 'Finished "%s"%s for %s at %s' % [
+ request.filtered_path,
+ websocket? ? ' [Websocket]' : '',
+ request.ip,
+ Time.now.to_default_s ]
+ end
+
end
end
end