Class: Supplejack::LogSubscriber
- Inherits:
-
ActiveSupport::LogSubscriber
- Object
- ActiveSupport::LogSubscriber
- Supplejack::LogSubscriber
- Defined in:
- lib/supplejack/log_subscriber.rb
Instance Method Summary collapse
- #api_environment ⇒ Object
- #colorize(text, color) ⇒ Object
-
#log_request(duration, payload, solr_request_params = {}) ⇒ Object
rubocop:disable Metrics/LineLength FIXME: make line 24 (request = “”) shorter.
Instance Method Details
#api_environment ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/supplejack/log_subscriber.rb', line 51 def api_environment case Supplejack.api_url when "http://api.digitalnz.org" then "Prod" when /(hippo.uat)|(api.uat)/ then "Staging" else "Dev" end end |
#colorize(text, color) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/supplejack/log_subscriber.rb', line 41 def colorize(text, color) if text.is_a?(Hash) "{#{text.map {|k, v| "#{k}: #{colorize(v, color)}" }.join(', ')}}" elsif text.is_a?(Array) "[#{text.map {|e| colorize(e, color) }.join(', ')}]" else "#{BOLD}#{color}#{text}#{CLEAR}" end end |
#log_request(duration, payload, solr_request_params = {}) ⇒ Object
rubocop:disable Metrics/LineLength FIXME: make line 24 (request = “”) shorter
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/supplejack/log_subscriber.rb', line 13 def log_request(duration, payload, solr_request_params={}) return unless Supplejack.enable_debugging solr_request_params ||= {} payload ||= {} payload.reverse_merge!({:params => {}, :options => {}, :payload => {}}) method = payload[:method] || :get name = '%s (%.1fms)' % ["Supplejack API #{api_environment}", duration] parameters = payload[:params].map { |k, v| "#{k}: #{colorize(v, BOLD)}" }.join(', ') body = payload[:payload].map { |k, v| "#{k}: #{colorize(v, BOLD)}" }.join(', ') = payload[:options].map { |k, v| "#{k}: #{colorize(v, BOLD)}" }.join(', ') request = "#{method.to_s.upcase} path=#{payload[:path]} params={#{parameters}}, body={#{body}} options={#{}}" if payload[:exception] info = "\n #{colorize('Exception', RED)} [ #{payload[:exception].join(', ')} ]" else info = "" if solr_request_params.try(:any?) solr_request_params = solr_request_params.map { |k, v| "#{k}: #{colorize(v, BOLD)}" }.join(', ') info = "\n #{colorize('SOLR Request', YELLOW)} [ #{solr_request_params} ]" end end debug " #{colorize(name, GREEN)} [ #{request} ] #{info}" end |