Browse Source

DevLoader ok

main
pvincent 3 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
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
end
end

35
lib/semantic/dev_loader.rb

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

2
lib/semantic/log_subscriber.rb

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

Loading…
Cancel
Save