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.

53 lines
1.9 KiB

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