Class: Logtail::Integrations::Rails::EventLogSubscriber
- Inherits:
-
Object
- Object
- Logtail::Integrations::Rails::EventLogSubscriber
- Defined in:
- lib/logtail-rails/event_log_subscriber.rb
Overview
A subscriber for Rails 8.1’s Structured Event Reporting system. This subscriber receives events emitted by Rails.event.notify() and logs them with all their data to Rails.logger, which sends them to Better Stack.
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Rails logger instance.
Instance Method Summary collapse
-
#emit(event) ⇒ Object
Rails 8.1 event emission method - called when events are emitted.
-
#initialize(logger) ⇒ EventLogSubscriber
constructor
Initialize the subscriber with a logger instance.
Constructor Details
#initialize(logger) ⇒ EventLogSubscriber
Initialize the subscriber with a logger instance
18 19 20 |
# File 'lib/logtail-rails/event_log_subscriber.rb', line 18 def initialize(logger) @logger = logger end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Rails logger instance
9 10 11 |
# File 'lib/logtail-rails/event_log_subscriber.rb', line 9 def logger @logger end |
Instance Method Details
#emit(event) ⇒ Object
Rails 8.1 event emission method - called when events are emitted
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/logtail-rails/event_log_subscriber.rb', line 23 def emit(event) return unless self.class.enabled # Log the event with all its data to Rails.logger # Create a structured log entry with the event data = event[:tags] = .is_a?(Hash) ? .keys : (.is_a?(Array) ? : []) log_data = { event_name: event[:name], payload: event[:payload] || {}, context: event[:context] || {}, tags: , source_location: event[:source_location] || {} } = (event) logger.send(self.class.log_level, , log_data) end |