|
@ -2,16 +2,26 @@ module Semantic |
|
|
# use the Zeitwerk autoloader to reattach_appender for development autoreloading feature |
|
|
# use the Zeitwerk autoloader to reattach_appender for development autoreloading feature |
|
|
class DevLoader |
|
|
class DevLoader |
|
|
def initialize |
|
|
def initialize |
|
|
|
|
|
@subscribers = [] |
|
|
|
|
|
force_preload_module |
|
|
Rails.autoloaders.main.on_load('ApplicationController') do |
|
|
Rails.autoloaders.main.on_load('ApplicationController') do |
|
|
append_ansi_formatter |
|
|
append_ansi_formatter |
|
|
append_subscriber_once |
|
|
|
|
|
|
|
|
register_log_subscriber |
|
|
end |
|
|
end |
|
|
append_ansi_formatter |
|
|
append_ansi_formatter |
|
|
|
|
|
|
|
|
|
|
|
# FIXME: when final |
|
|
# Rails.logger.level = :error |
|
|
# Rails.logger.level = :error |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
private |
|
|
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 |
|
|
def append_ansi_formatter |
|
|
SemanticLogger.clear_appenders! |
|
|
SemanticLogger.clear_appenders! |
|
|
formatter = Semantic::AnsiFormatter.new |
|
|
formatter = Semantic::AnsiFormatter.new |
|
@ -20,15 +30,16 @@ module Semantic |
|
|
filter: ->(log) { !formatter.reject(log) }) |
|
|
filter: ->(log) { !formatter.reject(log) }) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def append_subscriber_once |
|
|
|
|
|
return unless @previous_subscribe.nil? |
|
|
|
|
|
|
|
|
def register_log_subscriber |
|
|
|
|
|
@subscribers.each { |sub| ActiveSupport::Notifications.unsubscribe(sub) } |
|
|
|
|
|
@subscribers.clear |
|
|
|
|
|
|
|
|
subscriber = Semantic::LogSubscriber.new('toto1') |
|
|
|
|
|
@previous_subscribe = ActiveSupport::Notifications.subscribe 'start_processing.action_controller' do |event| |
|
|
|
|
|
subscriber.start_processing(event) |
|
|
|
|
|
|
|
|
log_subscriber = Semantic::LogSubscriber.new('toto1') |
|
|
|
|
|
@subscribers << ActiveSupport::Notifications.subscribe('start_processing.action_controller') do |event| |
|
|
|
|
|
log_subscriber.start_processing(event) |
|
|
end |
|
|
end |
|
|
ActiveSupport::Notifications.subscribe 'process_action.action_controller' do |event| |
|
|
|
|
|
subscriber.finish_processing(event) |
|
|
|
|
|
|
|
|
@subscribers << ActiveSupport::Notifications.subscribe('process_action.action_controller') do |event| |
|
|
|
|
|
log_subscriber.finish_processing(event) |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|