-
-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor log subscribers & create a new one to support logging of Action Cable events Monkey-patch Action Cable server class to silence default Action Cable logger Monkey-patch Action Cable Channel and Connection classes to support logging subscribe, unsubscribe, connect & disconnect events Update log formatters to support Action Cable log data
- Loading branch information
Showing
16 changed files
with
639 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Lograge | ||
module Formatters | ||
module Helpers | ||
module MethodAndPath | ||
def method_and_path_string(data) | ||
method_and_path = [data[:method], data[:path]].compact | ||
method_and_path.any?(&:present?) ? " #{method_and_path.join(' ')} " : ' ' | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Lograge | ||
module LogSubscribers | ||
class ActionCable < Base | ||
%i(perform_action subscribe unsubscribe connect disconnect).each do |method_name| | ||
define_method(method_name) do |event| | ||
process_main_event(event) | ||
end | ||
end | ||
|
||
private | ||
|
||
def initial_data(payload) | ||
{ | ||
method: {}, | ||
path: {}, | ||
format: {}, | ||
params: payload[:data], | ||
controller: payload[:channel_class] || payload[:connection_class], | ||
action: payload[:action] | ||
} | ||
end | ||
|
||
def default_status | ||
200 | ||
end | ||
|
||
def extract_runtimes(event, _payload) | ||
{ duration: event.duration.to_f.round(2) } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
module Lograge | ||
module LogSubscribers | ||
class ActionController < Base | ||
def process_action(event) | ||
process_main_event(event) | ||
end | ||
|
||
def redirect_to(event) | ||
RequestStore.store[:lograge_location] = event.payload[:location] | ||
end | ||
|
||
def unpermitted_parameters(event) | ||
RequestStore.store[:lograge_unpermitted_params] ||= [] | ||
RequestStore.store[:lograge_unpermitted_params].concat(event.payload[:keys]) | ||
end | ||
|
||
private | ||
|
||
def initial_data(payload) | ||
{ | ||
method: payload[:method], | ||
path: extract_path(payload), | ||
format: extract_format(payload), | ||
controller: payload[:controller], | ||
action: payload[:action] | ||
} | ||
end | ||
|
||
def extract_path(payload) | ||
path = payload[:path] | ||
strip_query_string(path) | ||
end | ||
|
||
def strip_query_string(path) | ||
index = path.index('?') | ||
index ? path[0, index] : path | ||
end | ||
|
||
if ::ActionPack::VERSION::MAJOR == 3 && ::ActionPack::VERSION::MINOR.zero? | ||
def extract_format(payload) | ||
payload[:formats].first | ||
end | ||
else | ||
def extract_format(payload) | ||
payload[:format] | ||
end | ||
end | ||
|
||
def extract_runtimes(event, payload) | ||
data = { duration: event.duration.to_f.round(2) } | ||
data[:view] = payload[:view_runtime].to_f.round(2) if payload.key?(:view_runtime) | ||
data[:db] = payload[:db_runtime].to_f.round(2) if payload.key?(:db_runtime) | ||
data | ||
end | ||
|
||
def extract_location | ||
location = RequestStore.store[:lograge_location] | ||
return {} unless location | ||
|
||
RequestStore.store[:lograge_location] = nil | ||
{ location: strip_query_string(location) } | ||
end | ||
|
||
def extract_unpermitted_params | ||
unpermitted_params = RequestStore.store[:lograge_unpermitted_params] | ||
return {} unless unpermitted_params | ||
|
||
RequestStore.store[:lograge_unpermitted_params] = nil | ||
{ unpermitted_params: unpermitted_params } | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.