|
|
@ -11,7 +11,8 @@ module Semantic |
|
|
|
end |
|
|
|
|
|
|
|
# FIXME: proper unsubscribe!!! |
|
|
|
RailsSemanticLogger::ActionController::LogSubscriber.logger.level = :fatal |
|
|
|
# RailsSemanticLogger::ActionController::LogSubscriber.logger.level = :fatal |
|
|
|
|
|
|
|
# |
|
|
|
# RailsSemanticLogger.swap_subscriber( |
|
|
|
# RailsSemanticLogger::ActionController::LogSubscriber, |
|
|
@ -62,7 +63,32 @@ module Semantic |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
def subscriber_patterns(subscriber) |
|
|
|
subscriber.patterns.respond_to?(:keys) ? subscriber.patterns.keys : subscriber.patterns |
|
|
|
end |
|
|
|
|
|
|
|
def unattach(subscriber, pattern) |
|
|
|
subscriber_patterns(subscriber).each do |sub_pattern| |
|
|
|
ActiveSupport::Notifications.notifier.listeners_for(sub_pattern).each do |sub| |
|
|
|
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' |
|
|
|
|
|
|
|
ActiveSupport::Notifications.unsubscribe(sub) |
|
|
|
ActiveSupport::LogSubscriber.subscribers.delete(subscriber) |
|
|
|
end |
|
|
|
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) } |
|
|
|
end |
|
|
|
|
|
|
|
def reset_subscribers |
|
|
|
clear_subscribers(/\.action_controller$/) |
|
|
|
if defined?(@subscribers) |
|
|
|
@subscribers.each { |sub| ActiveSupport::Notifications.unsubscribe(sub) } |
|
|
|
@subscribers.clear |
|
|
|