Module: Locksmith::Log

Extended by:
Log
Included in:
Log
Defined in:
lib/locksmith/log.rb

Instance Method Summary collapse

Instance Method Details

#log(data) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/locksmith/log.rb', line 5

def log(data)
  result = nil
  data = {:lib => "locksmith"}.merge(data)
  if block_given?
    start = Time.now
    result = yield
    data.merge(:elapsed => Time.now - start)
  end
  data.reduce(out=String.new) do |s, tup|
    s << [tup.first, tup.last].join("=") << " "
  end
  puts(out) if ENV["DEBUG"]
  return result
end