class Stracer::Recorder

Public Class Methods

new(stats, log, opts = {}) click to toggle source
# File lib/stracer/recorder.rb, line 3
def initialize(stats, log, opts = {})
  @log = log
  @stats = stats
  @host = opts[:host] || "unknown_host"
end

Public Instance Methods

error(message) click to toggle source
# File lib/stracer/recorder.rb, line 9
def error(message)
  @log.error(message)
end
fail(label, message) click to toggle source
# File lib/stracer/recorder.rb, line 22
def fail(label, message)
  error(message)
  @stats.increment "error.#{label}.#{@host}"
end
log(message) click to toggle source
# File lib/stracer/recorder.rb, line 13
def log(message)
  @log.info(message)
end
measure(key) { || ... } click to toggle source
# File lib/stracer/recorder.rb, line 27
def measure(key)
  start = Time.now
  result = yield
  timing(key, ((Time.now - start) * 1000).round)
  result
end
timing(key, value) click to toggle source
# File lib/stracer/recorder.rb, line 34
def timing(key, value)
  @stats.timing("#{key}.#{@host}", value)
  @log.debug("Traced total of #{value} for #{key}")
end
trace(label, message = nil) click to toggle source
# File lib/stracer/recorder.rb, line 17
def trace(label, message = nil)
  @log.debug(message) if message
  @stats.increment "#{label}.#{@host}"
end