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.

37 lines
1.4 KiB

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