Class: Elastics::Instrumentation::ActiveSupport::LogSubscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/elastics/instrumentation/active_support.rb

Instance Method Summary collapse

Instance Method Details

#http_request(event) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/elastics/instrumentation/active_support.rb', line 39

def http_request(event)
  return unless logger.debug?

  payload = event.payload[:args]
  method, path, query, body, params = payload
  path = '/' if path.blank?
  path << "?#{query.to_param}" if query.present?
  model = params[:model]

  name = ""
  name << "#{model.name} " if model
  name << "elastics (#{event.duration.round(1)}ms)"
  request = "#{method.to_s.upcase} #{path}"
  request << " #{Instrumentation.prettify_body(body)}" if body.present?

  if odd?
    name    = color(name, ::ActiveSupport::LogSubscriber::CYAN, true)
    request = color(request, nil, true)
  else
    name = color(name, ::ActiveSupport::LogSubscriber::MAGENTA, true)
  end

  debug "  #{name}  #{request}"
end

#odd?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/elastics/instrumentation/active_support.rb', line 64

def odd?
  @odd = !@odd
end