Log to a (configurable) file

This commit is contained in:
Scott Schneider 2013-11-08 10:48:51 -08:00
parent 2f4bdaf67a
commit 57975a489f
2 changed files with 12 additions and 4 deletions

View file

@ -1,13 +1,20 @@
require 'rubygems' unless defined?(Gem)
class Logger
def initialize
def initialize(
f = '/var/log/vmware-host-pooler.log'
)
@file = f
end
def log level, string
time = Time.new
stamp = time.strftime('%Y-%m-%d %H:%M:%S')
puts "[#{stamp}] #{string}"
open(@file, 'a') do |f|
f.puts "[#{stamp}] #{string}"
end
end
end

View file

@ -9,9 +9,6 @@ require 'lib/logger'
require 'lib/require_relative'
require 'lib/vsphere_helper'
$logger = Logger.new
$vsphere_helper = VsphereHelper.new
Dir.chdir(File.dirname(__FILE__))
# Load the configuration file
@ -21,6 +18,10 @@ config = YAML.load_file(config_file)
pools = config[:pools]
vsphere = config[:vsphere]
# Load logger & vSphere helper libraries
$logger = Logger.new config[:config]['logfile']
$vsphere_helper = VsphereHelper.new
# Connect to Redis
$redis = Redis.new