Class: U::Log::ActiveRecordSubscriber
- Inherits:
-
ActiveSupport::LogSubscriber
- Object
- ActiveSupport::LogSubscriber
- U::Log::ActiveRecordSubscriber
- Defined in:
- lib/u-log/active_record.rb
Instance Method Summary collapse
Instance Method Details
#identity(event) ⇒ Object
43 44 45 |
# File 'lib/u-log/active_record.rb', line 43 def identity(event) logger.ulogger.log(name: event.payload[:name], line: event.payload[:line]) end |
#render_bind(column, value) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/u-log/active_record.rb', line 8 def render_bind(column, value) if column if column.binary? value = "<#{value.bytesize} bytes of binary data>" end [column.name, value] else [nil, value] end end |
#sql(event) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/u-log/active_record.rb', line 20 def sql(event) payload = event.payload return if payload[:name] == 'SCHEMA' || payload[:name] == 'EXPLAIN' args = {} args[:name] = payload[:name] if payload[:name] args[:sql] = payload[:sql].squeeze(' ') if payload[:binds] && payload[:binds].any? args[:binds] = payload[:binds].inject({}) do |hash,(col, v)| k, v = render_bind(col, v) hash[k] = v hash end end args[:elapsed] = [event.duration.round(1), 'ms'] logger.ulogger.log(args) end |