Class: Editmode::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/editmode/logger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#httparty_subscriptionObject

Returns the value of attribute httparty_subscription.



5
6
7
# File 'lib/editmode/logger.rb', line 5

def httparty_subscription
  @httparty_subscription
end

Instance Method Details

#enable_httparty!Object



14
15
16
17
18
19
20
21
22
# File 'lib/editmode/logger.rb', line 14

def enable_httparty!
  @httparty_subscription = ActiveSupport::Notifications.subscribe('request.httparty') do |name, start, ending, transaction_id, payload|
    event = ActiveSupport::Notifications::Event.new(name, start, ending, transaction_id, payload)
    Rails.logger.info "  HTTParty -- " + "#{event.payload[:method]} #{event.payload[:url]} (Duration: #{event.duration}ms)"
    Thread.current[:http_runtime] ||= 0
    Thread.current[:http_runtime] += event.duration
    payload[:http_runtime] = event.duration
  end
end

#log_level=(level) ⇒ Object



7
8
9
10
11
12
# File 'lib/editmode/logger.rb', line 7

def log_level=(level)
  if level == :normal
    # Add more subscription here
    enable_httparty!
  end
end

#unsubscribe(subscriber) ⇒ Object



24
25
26
# File 'lib/editmode/logger.rb', line 24

def unsubscribe(subscriber)
  ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber.present?
end