vmpooler/lib/vmpooler/logger.rb
Glenn Sarti e04f380f42 (maint) Emit console messages when debugging is enabled
Previously all log messages may be written to a text file, however during
development or debugging it is also useful if the log messages are written to
the console.  This commit changes the logger class to emit messages to the
console, via `puts`, if the VMPOOLER_DEBUG environment variable is set.
2017-03-31 17:57:06 -07:00

22 lines
413 B
Ruby

require 'rubygems' unless defined?(Gem)
module Vmpooler
class Logger
def initialize(
f = '/var/log/vmpooler.log'
)
@file = f
end
def log(_level, string)
time = Time.new
stamp = time.strftime('%Y-%m-%d %H:%M:%S')
puts "[#{stamp}] #{string}" if ENV['VMPOOLER_DEBUG']
open(@file, 'a') do |f|
f.puts "[#{stamp}] #{string}"
end
end
end
end