You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

59 lines
1.7 KiB

module Semantic
NOTIFICATIONS = {
action_controller: %i[start_processing process_action redirect_to],
action_view: %i[render_partial render_template render_collection render_layout],
active_record: %i[sql strict_loading instantiation start_transaction transaction]
}.freeze
# enable/disable instrumentation callbacks
class Instrumentalizer
include SemanticLogger::Loggable
class << self
def activate(*event_groups)
reset
event_groups.each { |event_group| enable(event_group) }
end
private
def global_subscribers
@global_subscribers ||= []
end
def reset
global_subscribers.each do |sub|
ActiveSupport::Notifications.unsubscribe(sub)
end
global_subscribers.clear
NOTIFICATIONS.each do |event_group, hooks|
hooks.each do |hook|
hook_full_name = "#{hook}.#{event_group}"
ActiveSupport::Notifications.unsubscribe(hook_full_name)
end
end
end
def enable(event_group)
log_subscriber = build_log_subscriber_from(event_group)
NOTIFICATIONS[event_group].each do |hook|
subscriber = ActiveSupport::Notifications.subscribe("#{hook}.#{event_group}") do |event|
# logger.debug("SEND #{log_subscriber} hook=#{hook}")
log_subscriber.send(hook, event)
end
global_subscribers << subscriber
end
end
def build_log_subscriber_from(event_group)
classname = event_group.to_s.camelize
case classname
when 'ActionController'
Semantic::Subscribers.const_get(classname).new('toto1')
else
Semantic::Subscribers.const_get(classname).new
end
end
end
end
end