|
@ -3,28 +3,17 @@ module Semantic |
|
|
class DevLoader |
|
|
class DevLoader |
|
|
def initialize(session_key) |
|
|
def initialize(session_key) |
|
|
@session_key = session_key |
|
|
@session_key = session_key |
|
|
|
|
|
|
|
|
force_preload_module |
|
|
force_preload_module |
|
|
|
|
|
RailsSemanticLogger::ActionController::LogSubscriber.logger.level = :fatal |
|
|
|
|
|
clear_subscribers(/\.action_controller$/) |
|
|
|
|
|
|
|
|
once_and_reload do |
|
|
once_and_reload do |
|
|
|
|
|
clear_subscribers(/\.action_controller$/) |
|
|
append_ansi_formatter |
|
|
append_ansi_formatter |
|
|
|
|
|
reset_subscribers |
|
|
register_log_subscriber |
|
|
register_log_subscriber |
|
|
end |
|
|
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 |
|
|
end |
|
|
|
|
|
|
|
|
private |
|
|
private |
|
@ -47,7 +36,6 @@ module Semantic |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def register_log_subscriber |
|
|
def register_log_subscriber |
|
|
reset_subscribers |
|
|
|
|
|
register_to_action_controller(:start_processing) |
|
|
register_to_action_controller(:start_processing) |
|
|
register_to_action_controller(:process_action, :finish_processing) |
|
|
register_to_action_controller(:process_action, :finish_processing) |
|
|
register_to_action_controller(:redirect_to) |
|
|
register_to_action_controller(:redirect_to) |
|
@ -73,28 +61,31 @@ module Semantic |
|
|
next unless sub.instance_variable_get(:@delegate) == subscriber |
|
|
next unless sub.instance_variable_get(:@delegate) == subscriber |
|
|
next unless pattern.match(sub_pattern) |
|
|
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::Notifications.unsubscribe(sub) |
|
|
ActiveSupport::LogSubscriber.subscribers.delete(subscriber) |
|
|
|
|
|
end |
|
|
end |
|
|
|
|
|
ActiveSupport::LogSubscriber.subscribers.delete(subscriber) |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
# pattern could be either a string 'start_processing.action_controller' or a regex /\.action_controller$/ |
|
|
# pattern could be either a string 'start_processing.action_controller' or a regex /\.action_controller$/ |
|
|
def clear_subscribers(pattern) |
|
|
def clear_subscribers(pattern) |
|
|
ActiveSupport::LogSubscriber.subscribers.each { |sub| unattach(sub, pattern) } |
|
|
ActiveSupport::LogSubscriber.subscribers.each { |sub| unattach(sub, pattern) } |
|
|
|
|
|
ActiveSupport::Notifications.unsubscribe('start_processing.action_controller') |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def reset_subscribers |
|
|
def reset_subscribers |
|
|
clear_subscribers(/\.action_controller$/) |
|
|
|
|
|
if defined?(@subscribers) |
|
|
if defined?(@subscribers) |
|
|
@subscribers.each { |sub| ActiveSupport::Notifications.unsubscribe(sub) } |
|
|
|
|
|
|
|
|
@subscribers.each do |sub| |
|
|
|
|
|
ActiveSupport::Notifications.unsubscribe(sub) |
|
|
|
|
|
end |
|
|
@subscribers.clear |
|
|
@subscribers.clear |
|
|
else |
|
|
else |
|
|
@subscribers = [] |
|
|
@subscribers = [] |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
@log_subscriber = Semantic::LogSubscriber.new(@session_key) |
|
|
@log_subscriber = Semantic::LogSubscriber.new(@session_key) |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|