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.

41 lines
1.2 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
  1. module Semantic
  2. module Subscribers
  3. # LogSubscriber for event_group :active_record
  4. class ActiveRecord < LogSubscriber
  5. include AnsiColors
  6. IGNORE_PAYLOAD_NAMES = %w[SCHEMA EXPLAIN].freeze
  7. def sql(event)
  8. name = event.payload[:name]
  9. return if IGNORE_PAYLOAD_NAMES.include?(name)
  10. if name.end_with?('Load')
  11. name = event.payload[:cached] ? "#{name} (cached)" : "#{name} (#{event.payload[:row_count]})"
  12. end
  13. name = colorize(name, TEXT_CYAN)
  14. sql = colorize(event.payload[:sql], TEXT_BLUE)
  15. logger.debug("#{name} #{sql}")
  16. end
  17. def start_transaction(event)
  18. short_uuid = short_uuid(event.payload[:transaction].uuid)
  19. logger.info("TRANSACTION Begin #{short_uuid}")
  20. end
  21. def transaction(event)
  22. outcome = event.payload[:outcome]
  23. short_uuid = short_uuid(event.payload[:transaction].uuid)
  24. logger.info("TRANSACTION #{outcome.capitalize} #{short_uuid}")
  25. end
  26. def instantiation(event); end
  27. def strict_loading_violation(event) = any_hook event
  28. private
  29. def short_uuid(uuid) = uuid.split('-').first
  30. end
  31. end
  32. end