Class: Sqreen::PerformanceNotifications::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/sqreen/performance_notifications/log.rb

Overview

Log performances on the console

Direct Known Subclasses

LogPerformance, Metrics, NewRelic

Class Method Summary collapse

Class Method Details

.disableObject



34
35
36
37
38
# File 'lib/sqreen/performance_notifications/log.rb', line 34

def disable
  return if @subid.nil?
  Sqreen::PerformanceNotifications.unsubscribe(@subid)
  @subid = nil
end

.enable(facility = nil) ⇒ Object



28
29
30
31
32
# File 'lib/sqreen/performance_notifications/log.rb', line 28

def enable(facility = nil)
  return unless @subid.nil?
  @facility = facility
  @subid = Sqreen::PerformanceNotifications.subscribe(&method(:log))
end

.event_name(rule, cb) ⇒ Object



24
25
26
# File 'lib/sqreen/performance_notifications/log.rb', line 24

def event_name(rule, cb)
  "Callbacks/#{rule}/#{cb}"
end

.log(rule, cb, start, finish, meta) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/sqreen/performance_notifications/log.rb', line 15

def log(rule, cb, start, finish, meta)
  (@facility || Sqreen.log).debug do
    meta_str = nil
    meta_str = ": #{meta.inspect}" unless meta.empty?
    event = event_name(rule, cb)
    format('%s took %.2fms%s', event, (finish - start) * 1000, meta_str)
  end
end