Last active
December 15, 2015 23:49
-
-
Save ryandotsmith/5343120 to your computer and use it in GitHub Desktop.
A simple ruby logger that emits l2met conventional data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def log(data) | |
result = nil | |
if data.key?(:measure) | |
name = data.delete(:measure).insert(0, ENV["APP_NAME"] + ".") | |
end | |
if block_given? | |
start = Time.now | |
result = yield | |
elapsed = (Time.now.to_f - start.to_f) * 1000 | |
data.merge!("measure.#{name}" => elapsed.round) | |
else | |
data.merge!("measure.#{name}" => 1) | |
end | |
data.reduce(out=String.new) do |s, tup| | |
quoted_tup = tup.last.is_a?(String) ? "\"#{tup.last}\"" : tup.last | |
s << [tup.first, quoted_tup].join("=") << " " | |
end | |
$stdout.puts(out) | |
return result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: