You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

46 lines
1.4 KiB

module Semantic
# use the Zeitwerk autoloader to reattach_appender for development autoreloading feature
class DevLoader
def initialize
@subscribers = []
force_preload_module
Rails.autoloaders.main.on_load('ApplicationController') do
append_ansi_formatter
register_log_subscriber
end
append_ansi_formatter
# FIXME: when final
# Rails.logger.level = :error
end
private
def force_preload_module
self.class.module_parent.constants.each do |const|
self.class.module_parent.const_get(const)
end
end
def append_ansi_formatter
SemanticLogger.clear_appenders!
formatter = Semantic::AnsiFormatter.new
SemanticLogger.add_appender(io: $stdout,
formatter:,
filter: ->(log) { !formatter.reject(log) })
end
def register_log_subscriber
@subscribers.each { |sub| ActiveSupport::Notifications.unsubscribe(sub) }
@subscribers.clear
log_subscriber = Semantic::LogSubscriber.new('toto1')
@subscribers << ActiveSupport::Notifications.subscribe('start_processing.action_controller') do |event|
log_subscriber.start_processing(event)
end
@subscribers << ActiveSupport::Notifications.subscribe('process_action.action_controller') do |event|
log_subscriber.finish_processing(event)
end
end
end
end