Created
May 19, 2014 03:02
-
-
Save jschairb/dbe4db2ec02eed540c08 to your computer and use it in GitHub Desktop.
Messing around w/ some metric logging
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
require 'logger' | |
require 'json' | |
class LagerFormatter < Logger::Formatter | |
def self.call(severity, time, prg_name, message) | |
defaults = { | |
:severity => severity, | |
:time => time, | |
:prg_name => prg_name | |
} | |
defaults.merge(message).to_json | |
end | |
end | |
class Lager | |
attr_reader :log | |
def initialize | |
@log = Logger.new(STDOUT) | |
@log.datetime_format = "%FT%T%:z" | |
@log.formatter = LagerFormatter | |
@log.progname = "cloud-control" | |
end | |
end | |
class Transcript | |
def initialize | |
@log = Lager.new | |
end | |
def log_around(&block) | |
start_time = Time.now | |
yield | |
end_time = Time.now | |
execution_time = end_time - start_time | |
@log.log.debug({ :execution => execution_time, :message => "it worked" }) | |
end | |
end | |
transcript = Transcript.new | |
transcript.log_around do | |
sleep 3 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment