Sha256: f2e665b537df58575e5f9985a4a564f1f51e09e4ae72b764825d8316f9034110

Contents?: true

Size: 1.09 KB

Versions: 38

Compression:

Stored size: 1.09 KB

Contents

# Copyright (c) 2015 Sqreen. All Rights Reserved.
# Please refer to our terms for more information: https://www.sqreen.io/terms.html

require 'sqreen/performance_notifications'

module Sqreen
  module PerformanceNotifications
    # Log performances on the console
    class Log
      @subid = nil
      @facility = nil
      class << self
        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

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

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

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

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
sqreen-1.18.1-java lib/sqreen/performance_notifications/log.rb
sqreen-1.18.1 lib/sqreen/performance_notifications/log.rb
sqreen-1.18.0-java lib/sqreen/performance_notifications/log.rb
sqreen-1.18.0 lib/sqreen/performance_notifications/log.rb
sqreen-1.17.2-java lib/sqreen/performance_notifications/log.rb
sqreen-1.17.2 lib/sqreen/performance_notifications/log.rb
sqreen-1.17.2.rc1-java lib/sqreen/performance_notifications/log.rb
sqreen-1.17.2.rc1 lib/sqreen/performance_notifications/log.rb
sqreen-1.17.2.beta4-java lib/sqreen/performance_notifications/log.rb
sqreen-1.17.2.beta4 lib/sqreen/performance_notifications/log.rb
sqreen-1.17.2.beta3-java lib/sqreen/performance_notifications/log.rb
sqreen-1.17.2.beta3 lib/sqreen/performance_notifications/log.rb
sqreen-1.17.2.beta2-java lib/sqreen/performance_notifications/log.rb
sqreen-1.17.2.beta2 lib/sqreen/performance_notifications/log.rb
sqreen-1.17.2.beta1-java lib/sqreen/performance_notifications/log.rb
sqreen-1.17.2.beta1 lib/sqreen/performance_notifications/log.rb
sqreen-1.17.0-java lib/sqreen/performance_notifications/log.rb
sqreen-1.17.0 lib/sqreen/performance_notifications/log.rb
sqreen-1.16.2-java lib/sqreen/performance_notifications/log.rb
sqreen-1.16.2 lib/sqreen/performance_notifications/log.rb