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.

39 lines
1.4 KiB

2 months ago
2 months ago
  1. return if Rails.application.tailwind_watcher?
  2. return unless Rails.application.server?
  3. if Rails.env.development?
  4. RailsSemanticLogger::Rack::Logger.logger.level = :info # useful for remaining log like "[Rack::Log] Started..."
  5. SemanticLogger.clear_appenders!
  6. Rails.logger.name = 'rails'
  7. end
  8. def build_instrumentation_config
  9. {
  10. action_controller: true,
  11. action_view: Live::Constants::ACTION_VIEW,
  12. active_record: Live::Constants::ACTIVE_RECORD
  13. }.map do |key, value|
  14. key if value
  15. end.compact
  16. end
  17. Rails.configuration.after_initialize do
  18. ActiveSupport::Notifications.subscribe('rolling.live_constant') do |event|
  19. constants = event.payload[:changes].map { |change| change[:constant] }
  20. if constants.intersection(%w[ACTIVE_RECORD ACTION_VIEW]).any?
  21. Semantic::Instrumentalizer.activate(*build_instrumentation_config)
  22. end
  23. end
  24. end
  25. Rails.autoloaders.main.on_load('ApplicationController') do
  26. SemanticLogger.clear_appenders!
  27. SemanticLogger.add_appender(io: $stdout, formatter: Rails.application.config.x.semantic.formatter.constantize.new)
  28. Rails.logger.info ' ', dimensions: Semantic::FancyDimensions.new(rails: '╔═╗', before: 1)
  29. Rails.logger.fatal 'Zeitwerk RELOAD!', dimensions: Semantic::FancyDimensions.new(rails: '╠█╣')
  30. Rails.logger.info ' ', dimensions: Semantic::FancyDimensions.new(rails: '╚═╝')
  31. Semantic::Instrumentalizer.activate(*build_instrumentation_config)
  32. end