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.

60 lines
2.3 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. return if Rails.application.tailwind_watcher?
  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. SemanticLogger.default_level = :debug
  16. Rails.logger.name = 'rails'
  17. if Rails.env.production?
  18. appender = :syslog
  19. formatter = Rails.application.config.x.semantic.formatter.constantize.new
  20. SemanticLogger.add_appender(appender:, formatter:)
  21. Semantic::Instrumentalizer.activate(*build_instrumentation_config)
  22. if Rails.application.rake? || Rails.application.console?
  23. io_formatter = Rails.application.config.x.semantic.formatter.constantize.new(time_format: '%H:%M:%S')
  24. SemanticLogger.add_appender(io: $stdout, formatter: io_formatter)
  25. end
  26. else
  27. time_format = '%H:%M:%S' unless Rails.application.procfile_server?
  28. SemanticLogger.clear_appenders!
  29. SemanticLogger.add_appender(
  30. io: $stdout,
  31. formatter: Rails.application.config.x.semantic.formatter.constantize.new(time_format:)
  32. )
  33. Rails.autoloaders.main.on_load('ApplicationController') do
  34. SemanticLogger.clear_appenders!
  35. SemanticLogger.add_appender(
  36. io: $stdout,
  37. formatter: Rails.application.config.x.semantic.formatter.constantize.new(time_format:)
  38. )
  39. Rails.logger.info ' ', dimensions: Semantic::FancyDimensions.new(rails: '╔═╗', before: 1)
  40. Rails.logger.fatal 'Zeitwerk RELOAD!', dimensions: Semantic::FancyDimensions.new(rails: '╠█╣')
  41. Rails.logger.info ' ', dimensions: Semantic::FancyDimensions.new(rails: '╚═╝')
  42. Semantic::Instrumentalizer.activate(*build_instrumentation_config)
  43. end
  44. ActiveSupport::Notifications.subscribe('rolling.live_constant') do |event|
  45. constants = event.payload[:changes].map { |change| change[:constant] }
  46. if constants.intersection(%w[ACTIVE_RECORD ACTION_VIEW]).any?
  47. Semantic::Instrumentalizer.activate(*build_instrumentation_config)
  48. end
  49. end
  50. end
  51. end