diff --git a/app/controllers/scores_controller.rb b/app/controllers/scores_controller.rb index a817261..9723565 100644 --- a/app/controllers/scores_controller.rb +++ b/app/controllers/scores_controller.rb @@ -5,7 +5,6 @@ class ScoresController < ApplicationController before_action :set_score, only: %i[show edit update destroy] def index - logger.info 'index called A' @q = Score.all.ransack(q_params) @pagy, @scores = pagy(@q.result) end diff --git a/config/environments/development.rb b/config/environments/development.rb index a06056e..513ecae 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -87,33 +87,8 @@ Rails.application.configure do # rubocop:disable Metrics/BlockLength # filter: ->(log) { !formatter.reject(log) }) end elsif Rails.application.server? - config.after_initialize do - source_location = Semantic::AnsiFormatter.instance_method(:initialize).source_location[0] - previous_mtime = File.stat(source_location).mtime - formatter = Semantic::AnsiFormatter.new - # SemanticLogger.clear_appenders! - SemanticLogger.add_appender(io: $stdout, - formatter:, - filter: ->(log) { !formatter.reject(log) }) - - [Semantic::AnsiFormatter, ApplicationController].each do |class_name| - Rails.autoloaders.main.on_load(class_name.to_s) do |klass, abspath| - if klass == Semantic::AnsiFormatter - mtime = File.stat(source_location).mtime - if previous_mtime != mtime - previous_mtime = mtime - SemanticLogger.clear_appenders! - formatter = Semantic::AnsiFormatter.new - SemanticLogger.add_appender(io: $stdout, - formatter:, - filter: lambda { |log| - !formatter.reject(log) - }) - end - end - end - end + Semantic::DevLoader.new end end end diff --git a/lib/semantic/ansi_formatter.rb b/lib/semantic/ansi_formatter.rb index 4afc501..a427079 100644 --- a/lib/semantic/ansi_formatter.rb +++ b/lib/semantic/ansi_formatter.rb @@ -28,7 +28,7 @@ module Semantic end def call(log, logger) - # puts 'ok1' + # puts 'ok2' log = alter(log) self.log = log diff --git a/lib/semantic/dev_loader.rb b/lib/semantic/dev_loader.rb new file mode 100644 index 0000000..10d5454 --- /dev/null +++ b/lib/semantic/dev_loader.rb @@ -0,0 +1,19 @@ +module Semantic + # use the Zeitwerk autoloader to reattach_appender for development autoreloading feature + class DevLoader + def initialize + Rails.autoloaders.main.on_load('ApplicationController') { append_ansi_formatter } + append_ansi_formatter + end + + private + + def append_ansi_formatter + SemanticLogger.clear_appenders! + formatter = Semantic::AnsiFormatter.new + SemanticLogger.add_appender(io: $stdout, + formatter:, + filter: ->(log) { !formatter.reject(log) }) + end + end +end