Module: Vault::Log
- Defined in:
- lib/vault-tools/log.rb
Class Method Summary collapse
-
.count(name, value = 1, extra_data = {}) ⇒ Object
Log a count metric.
-
.count_status(status) ⇒ Object
Log an HTTP status code.
-
.log(data, &block) ⇒ Object
Write a message with key/value pairs to the log stream.
-
.measure(name, value, extra_data = {}) ⇒ Object
Log a measurement.
-
.time(name, duration) ⇒ Object
Log a timing metric.
Class Method Details
.count(name, value = 1, extra_data = {}) ⇒ Object
Log a count metric.
8 9 10 |
# File 'lib/vault-tools/log.rb', line 8 def self.count(name, value = 1, extra_data = {}) log(extra_data.merge("count##{Config.app_name}.#{name}" => value)) end |
.count_status(status) ⇒ Object
Log an HTTP status code. Two log metrics are written each time this method is invoked:
- The first one emits a metric called
http_200
for an HTTP 200 response. - The second one emits a metric called
http_2xx
for the same code.
This makes it possible to easily measure individual HTTP status codes as well as classes of HTTP status codes.
23 24 25 26 27 28 |
# File 'lib/vault-tools/log.rb', line 23 def self.count_status(status) count("http.#{status}") if status_prefix = status.to_s.match(/\d/)[0] count("http.#{status_prefix}xx") end end |
.log(data, &block) ⇒ Object
Write a message with key/value pairs to the log stream.
59 60 61 62 63 64 |
# File 'lib/vault-tools/log.rb', line 59 def self.log(data, &block) data['source'] ||= Config.app_deploy if Config.app_deploy data['app'] ||= Config.app_name if Config.app_name data['request-id'] = Thread.current[:request_id] if Thread.current[:request_id] Scrolls.log(data, &block) end |
.measure(name, value, extra_data = {}) ⇒ Object
Log a measurement.
35 36 37 |
# File 'lib/vault-tools/log.rb', line 35 def self.measure(name, value, extra_data = {}) log(extra_data.merge("measure##{Config.app_name}.#{name}" => value)) end |
.time(name, duration) ⇒ Object
Log a timing metric.
43 44 45 46 47 48 49 50 51 |
# File 'lib/vault-tools/log.rb', line 43 def self.time(name, duration) if name name.gsub(/\/:\w+/, ''). # Remove param names from path. gsub(/[\/_]+/, "-"). # Replace slash with dash. gsub(/[^A-Za-z0-9\-\_]/, ''). # Only keep subset of chars. sub(/^-+/, ""). # Strip the leading dashes. tap { |name| measure(name, "#{duration}ms") } end end |