|
|
@ -3,28 +3,17 @@ module Semantic |
|
|
|
class DevLoader |
|
|
|
def initialize(session_key) |
|
|
|
@session_key = session_key |
|
|
|
|
|
|
|
force_preload_module |
|
|
|
RailsSemanticLogger::ActionController::LogSubscriber.logger.level = :fatal |
|
|
|
clear_subscribers(/\.action_controller$/) |
|
|
|
|
|
|
|
once_and_reload do |
|
|
|
clear_subscribers(/\.action_controller$/) |
|
|
|
append_ansi_formatter |
|
|
|
reset_subscribers |
|
|
|
register_log_subscriber |
|
|
|
end |
|
|
|
|
|
|
|
# FIXME: proper unsubscribe!!! |
|
|
|
# RailsSemanticLogger::ActionController::LogSubscriber.logger.level = :fatal |
|
|
|
|
|
|
|
# |
|
|
|
# RailsSemanticLogger.swap_subscriber( |
|
|
|
# RailsSemanticLogger::ActionController::LogSubscriber, |
|
|
|
# @log_subscriber, # attach missing!!! |
|
|
|
# :action_controller |
|
|
|
# ) |
|
|
|
|
|
|
|
# ActiveSupport::LogSubscriber.subscribers.each do |sub| |
|
|
|
# puts "subscriber #{sub.pattern}" |
|
|
|
# end |
|
|
|
# RailsSemanticLogger.swap_subscriber(RailsSemanticLogger::ActionController::LogSubscriber, |
|
|
|
# @log_subscriber, :action_controller) |
|
|
|
end |
|
|
|
|
|
|
|
private |
|
|
@ -47,7 +36,6 @@ module Semantic |
|
|
|
end |
|
|
|
|
|
|
|
def register_log_subscriber |
|
|
|
reset_subscribers |
|
|
|
register_to_action_controller(:start_processing) |
|
|
|
register_to_action_controller(:process_action, :finish_processing) |
|
|
|
register_to_action_controller(:redirect_to) |
|
|
@ -73,28 +61,31 @@ module Semantic |
|
|
|
next unless sub.instance_variable_get(:@delegate) == subscriber |
|
|
|
next unless pattern.match(sub_pattern) |
|
|
|
|
|
|
|
# puts "FOUND subscriber=#{subscriber} for sub_pattern=#{sub_pattern} with logger #{subscriber.logger.name}" |
|
|
|
# puts 'remove notification then log_subscriber' |
|
|
|
puts "FOUND subscriber=#{subscriber} for sub_pattern=#{sub_pattern} with logger #{subscriber.logger.name}" |
|
|
|
puts subscriber.class.module_parent.const_source_location(subscriber.class.to_s)&.first |
|
|
|
|
|
|
|
ActiveSupport::Notifications.unsubscribe(sub) |
|
|
|
ActiveSupport::LogSubscriber.subscribers.delete(subscriber) |
|
|
|
end |
|
|
|
ActiveSupport::LogSubscriber.subscribers.delete(subscriber) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
# pattern could be either a string 'start_processing.action_controller' or a regex /\.action_controller$/ |
|
|
|
def clear_subscribers(pattern) |
|
|
|
ActiveSupport::LogSubscriber.subscribers.each { |sub| unattach(sub, pattern) } |
|
|
|
ActiveSupport::Notifications.unsubscribe('start_processing.action_controller') |
|
|
|
end |
|
|
|
|
|
|
|
def reset_subscribers |
|
|
|
clear_subscribers(/\.action_controller$/) |
|
|
|
if defined?(@subscribers) |
|
|
|
@subscribers.each { |sub| ActiveSupport::Notifications.unsubscribe(sub) } |
|
|
|
@subscribers.each do |sub| |
|
|
|
ActiveSupport::Notifications.unsubscribe(sub) |
|
|
|
end |
|
|
|
@subscribers.clear |
|
|
|
else |
|
|
|
@subscribers = [] |
|
|
|
end |
|
|
|
|
|
|
|
@log_subscriber = Semantic::LogSubscriber.new(@session_key) |
|
|
|
end |
|
|
|
end |
|
|
|