Class: VagrantCloud::Instrumentor::Logger
- Includes:
- Logger
- Defined in:
- lib/vagrant_cloud/instrumentor/logger.rb
Constant Summary collapse
- REDACTED =
"REDACTED".freeze
Instance Method Summary collapse
-
#excon(event, params) ⇒ Hash
Generate information based on excon event.
-
#format_output(info) ⇒ String
Format output to make it look nicer.
-
#instrument(name, params = {}) ⇒ Object
Perform event logging.
Methods included from Logger
Instance Method Details
#excon(event, params) ⇒ Hash
Generate information based on excon event
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/vagrant_cloud/instrumentor/logger.rb', line 55 def excon(event, params) # Remove noisy stuff that may be present from excon params.delete(:connection) params.delete(:stack) # Remove any credential information params[:password] = REDACTED if params.key?(:password) params[:access_token] = REDACTED if params[:access_token] if params.dig(:headers, "Authorization") || params.dig(:headers, "Proxy-Authorization") params[:headers] = params[:headers].dup.tap do |h| h["Authorization"] = REDACTED if h["Authorization"] h["Proxy-Authorization"] = REDACTED if h["Proxy-Authorization"] end end if params.dig(:proxy, :password) params[:proxy] = params[:proxy].dup.tap do |proxy| proxy[:password] = REDACTED end end info = {} case event when "request", "retry" info[:method] = params[:method] info[:identifier] = params.dig(:headers, 'X-Request-Id') info[:url] = "#{params[:scheme]}://#{File.join(params[:host], params[:path])}" info[:query] = params[:query] if params[:query] info[:headers] = params[:headers] if params[:headers] when "response" info[:status] = params[:status] info[:identifier] = params.dig(:headers, 'X-Request-Id') info[:body] = params[:body] else info = params.dup end duration = (params.dig(:timing, :duration).to_f * 1000).to_i info[:duration] = "#{duration}ms" info end |
#format_output(info) ⇒ String
Format output to make it look nicer
41 42 43 44 45 46 47 48 |
# File 'lib/vagrant_cloud/instrumentor/logger.rb', line 41 def format_output(info) info.map do |key, value| if value.is_a?(Enumerable) value = value.map{ |k,v| [k, v].compact.join(": ") }.join(", ") end "#{key}=#{value.inspect}" end.join(" ") end |
#instrument(name, params = {}) ⇒ Object
Perform event logging
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/vagrant_cloud/instrumentor/logger.rb', line 12 def instrument(name, params = {}) namespace, event = name.split(".", 2) if event == "error" logger.error { "#{namespace} #{event.upcase} #{params[:error]}" } return end logger.info do case namespace when "excon" # Make a copy so we can modify params = params.dup info = excon(event, params) else info = params.dup end "#{namespace} #{event.upcase} #{format_output(info)}" end logger.debug do "#{namespace} #{event.upcase} #{format_output(params)}" end end |