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.

31 lines
940 B

3 months ago
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. # Rails.logger.level = :error
  11. end
  12. private
  13. def append_ansi_formatter
  14. SemanticLogger.clear_appenders!
  15. formatter = Semantic::AnsiFormatter.new
  16. SemanticLogger.add_appender(io: $stdout,
  17. formatter:,
  18. filter: ->(log) { !formatter.reject(log) })
  19. end
  20. def append_subscriber_once
  21. return unless @previous_subscribe.nil?
  22. @previous_subscribe = ActiveSupport::Notifications.subscribe 'start_processing.action_controller' do |event|
  23. Semantic::LogSubscriber.new.start_processing(event)
  24. end
  25. end
  26. end
  27. end