Browse Source

semantic_logger auto_reload

main
pvincent 4 months ago
parent
commit
625fbc5780
  1. 1
      app/controllers/scores_controller.rb
  2. 43
      config/environments/development.rb
  3. 1
      lib/semantic/ansi_formatter.rb

1
app/controllers/scores_controller.rb

@ -5,6 +5,7 @@ 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

43
config/environments/development.rb

@ -77,10 +77,43 @@ Rails.application.configure do # rubocop:disable Metrics/BlockLength
routes.default_url_options[:port] = ARGV[1] # ie: Procfile.dev --port PORT
routes.default_url_options[:host] = '127.0.0.1'
config.after_initialize do
formatter = Semantic::AnsiFormatter.new
config.semantic_logger.add_appender(io: $stdout,
formatter:,
filter: ->(log) { !formatter.reject(log) })
if Rails.application.console?
config.after_initialize do
formatter = Semantic::BasicFormatter.new
SemanticLogger.add_appender(io: $stdout, formatter:)
# SemanticLogger.add_appender(io: $stdout,
# formatter:,
# 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
end
end
end

1
lib/semantic/ansi_formatter.rb

@ -28,6 +28,7 @@ module Semantic
end
def call(log, logger)
# puts 'ok1'
log = alter(log)
self.log = log

Loading…
Cancel
Save