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.

30 lines
904 B

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
  1. module Semantic
  2. # use the Zeitwerk autoloader to reattach_appender for development autoreloading feature
  3. class DevLoader
  4. def initialize
  5. Rails.autoloaders.main.on_load('ApplicationController') do
  6. append_ansi_formatter
  7. append_subscriber_once
  8. end
  9. append_ansi_formatter
  10. end
  11. private
  12. def append_ansi_formatter
  13. SemanticLogger.clear_appenders!
  14. formatter = Semantic::AnsiFormatter.new
  15. SemanticLogger.add_appender(io: $stdout,
  16. formatter:,
  17. filter: ->(log) { !formatter.reject(log) })
  18. end
  19. def append_subscriber_once
  20. return unless @previous_subscribe.nil?
  21. @previous_subscribe = ActiveSupport::Notifications.subscribe 'start_processing.action_controller' do |event|
  22. Semantic::LogSubscriber.new.start_processing(event)
  23. end
  24. end
  25. end
  26. end