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.

65 lines
2.4 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
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. SemanticLogger.clear_appenders!
  28. SemanticLogger.add_appender(
  29. io: $stdout,
  30. formatter: Rails.application.config.x.semantic.formatter.constantize.new(
  31. time_format: Rails.application.procfile_server? ? nil : '%H:%M:%S'
  32. )
  33. )
  34. ActiveSupport::Notifications.subscribe('rolling.live_constant') do |event|
  35. constants = event.payload[:changes].map { |change| change[:constant] }
  36. if constants.intersection(%w[ACTIVE_RECORD ACTION_VIEW]).any?
  37. Semantic::Instrumentalizer.activate(*build_instrumentation_config)
  38. end
  39. end
  40. Rails.autoloaders.main.on_load('ApplicationController') do
  41. SemanticLogger.clear_appenders!
  42. SemanticLogger.add_appender(
  43. io: $stdout,
  44. formatter: Rails.application.config.x.semantic.formatter.constantize.new(
  45. time_format: Rails.application.procfile_server? ? nil : '%H:%M:%S'
  46. )
  47. )
  48. Rails.logger.info ' ', dimensions: Semantic::FancyDimensions.new(rails: '╔═╗', before: 1)
  49. Rails.logger.fatal 'Zeitwerk RELOAD!', dimensions: Semantic::FancyDimensions.new(rails: '╠█╣')
  50. Rails.logger.info ' ', dimensions: Semantic::FancyDimensions.new(rails: '╚═╝')
  51. Semantic::Instrumentalizer.activate(*build_instrumentation_config)
  52. end
  53. end
  54. end