Created
October 30, 2017 11:50
-
-
Save jonquach/8c3c90634811f6b063772bc5a9a6e7c6 to your computer and use it in GitHub Desktop.
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
module Timber | |
module Integrations | |
module ActionController | |
class LogSubscriber < Integrator | |
# The log subscriber that replaces the default `ActionController::LogSubscriber`. | |
# The intent of this subscriber is to, as transparently as possible, properly | |
# track events that are being logged here. This LogSubscriber will never change | |
# default behavior / log messages. | |
# | |
# @private | |
class TimberLogSubscriber < ::ActionController::LogSubscriber | |
def start_processing(event) | |
return true if silence? | |
info do | |
payload = event.payload | |
params = payload[:params].except(*INTERNAL_PARAMS) | |
format = extract_format(payload) | |
format = format.to_s.upcase if format.is_a?(Symbol) | |
Events::ControllerCall.new( | |
controller: payload[:controller], | |
action: payload[:action], | |
format: format, | |
params: params | |
) | |
end | |
end | |
def unpermitted_parameters(event) | |
info do | |
unpermitted_keys = event.payload[:keys] | |
"Unpermitted parameter#{'s' if unpermitted_keys.size > 1}: #{unpermitted_keys.map { |e| ":#{e}" }.join(", ")}" | |
end | |
end | |
private | |
def extract_format(payload) | |
if payload.key?(:format) | |
payload[:format] # rails > 4.X | |
elsif payload.key?(:formats) | |
payload[:formats].first # rails 3.X | |
end | |
end | |
def silence? | |
ActionController.silence? | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment