Class: Timber::Integrations::ActiveRecord::LogSubscriber::TimberLogSubscriber

Inherits:
ActiveRecord::LogSubscriber
  • Object
show all
Defined in:
lib/timber-rails/active_record/log_subscriber/timber_log_subscriber.rb

Overview

The log subscriber that replaces the default ‘ActiveRecord::LogSubscriber`. The intent of this subscriber is to, as transparently as possible, properly track events that are being logged here. This LogSubscriber will never change default behavior / log messages.

Instance Method Summary collapse

Instance Method Details

#sql(event) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/timber-rails/active_record/log_subscriber/timber_log_subscriber.rb', line 18

def sql(event)
  return true if silence?

  r = super(event)

  if @message
    payload = event.payload

    sql_event = Events::SQLQuery.new(
      sql: payload[:sql],
      duration_ms: event.duration,
      message: @message,
    )

    logger.debug sql_event

    @message = nil
  end

  r
end