Browse Source

DevLoader ok

main
pvincent 2 months ago
parent
commit
8b2ae7e505
  1. 3
      config/application.rb
  2. 35
      lib/semantic/dev_loader.rb
  3. 2
      lib/semantic/log_subscriber.rb

3
config/application.rb

@ -35,9 +35,6 @@ module EasyGoingRails
# Customized Semantic Logger # Customized Semantic Logger
config.rails_semantic_logger.semantic = false config.rails_semantic_logger.semantic = false
config.rails_semantic_logger.started = true
config.rails_semantic_logger.processing = true
config.rails_semantic_logger.rendered = true
config.rails_semantic_logger.add_file_appender = false config.rails_semantic_logger.add_file_appender = false
end end
end end

35
lib/semantic/dev_loader.rb

@ -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

2
lib/semantic/log_subscriber.rb

@ -2,7 +2,7 @@ module Semantic
class LogSubscriber < ActiveSupport::LogSubscriber class LogSubscriber < ActiveSupport::LogSubscriber
include SemanticLogger::Loggable include SemanticLogger::Loggable
include AnsiColors include AnsiColors
def logger = SemanticLogger['IRails']
def logger = SemanticLogger['Rails']
INTERNAL_PARAMS = %i[controller action format _method only_path].freeze INTERNAL_PARAMS = %i[controller action format _method only_path].freeze
DEFAULT_DEV_HOSTS = ['127.0.0.1', 'localhost'].freeze DEFAULT_DEV_HOSTS = ['127.0.0.1', 'localhost'].freeze

Loading…
Cancel
Save