module KOAUtils::Logger

Public Class Methods

appname() click to toggle source
# File lib/koa-utils/logger.rb, line 28
def self.appname
  @prefix ||= ENV['APP_NAME'].downcase if ENV['APP_NAME']
  if defined? ::Rails
    @prefix ||= Rails.application.class.parent_name.downcase+"."
  end
  @prefix ||= ""
end
count(name, val, data = {}) click to toggle source
# File lib/koa-utils/logger.rb, line 66
def self.count(name, val, data = {})
  librato_log("count", name, val, data)
end
librato_log(type, name, val, data) click to toggle source
# File lib/koa-utils/logger.rb, line 40
def self.librato_log(type, name, val, data)
  name = prefix(name)
  data["#{type}##{name}"] = val
  log(data)
end
log(data) click to toggle source
# File lib/koa-utils/logger.rb, line 54
def self.log(data)
  out.puts(stringify(data))
end
measure(name, val, data = {}) click to toggle source
# File lib/koa-utils/logger.rb, line 70
def self.measure(name, val, data = {})
  librato_log("measure", name, val, data)
end
measure_block(name, data = {}) { || ... } click to toggle source
# File lib/koa-utils/logger.rb, line 58
def self.measure_block(name, data = {})
  start = Time.now
  result = yield
  elapsed = (Time.now.to_f - start.to_f) * 1000
  measure(name, elapsed.round.to_s+"ms")
  result
end
out() click to toggle source
# File lib/koa-utils/logger.rb, line 50
def self.out
  @out || $stdout
end
out=(o) click to toggle source
# File lib/koa-utils/logger.rb, line 46
def self.out=(o)
  @out = o
end
prefix(name) click to toggle source
# File lib/koa-utils/logger.rb, line 36
def self.prefix(name)
  appname+name
end
sample(name, val, data = {}) click to toggle source
# File lib/koa-utils/logger.rb, line 74
def self.sample(name, val, data = {})
  librato_log("sample", name, val, data)
end
stringify(data) click to toggle source
# File lib/koa-utils/logger.rb, line 78
def self.stringify(data)
  data.reduce(out=String.new) do |s, tup|
    s << [tup.first, tup.last].join("=") << " "
  end
end