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. if Rails.env.development?
  3. RailsSemanticLogger::Rack::Logger.logger.level = :info # useful for remaining log like "[Rack::Log] Started..."
  4. SemanticLogger.clear_appenders!
  5. Rails.logger.name = 'rails'
  6. end
  7. def build_instrumentation_config
  8. {
  9. action_controller: true,
  10. action_view: Live::Constants::ACTION_VIEW,
  11. active_record: Live::Constants::ACTIVE_RECORD
  12. }.map do |key, value|
  13. key if value
  14. end.compact
  15. end
  16. Rails.configuration.after_initialize do
  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