Remove util.rb and that logger
This commit is contained in:
parent
377fa1f7cc
commit
3cef90cfb9
|
@ -11,6 +11,6 @@ end
|
||||||
require File.expand_path("util/glob_loader", libdir)
|
require File.expand_path("util/glob_loader", libdir)
|
||||||
|
|
||||||
# Load them up
|
# Load them up
|
||||||
Vagrant::GlobLoader.glob_require(libdir, %w{util util/stacked_proc_runner util/progress_meter
|
Vagrant::GlobLoader.glob_require(libdir, %w{util/stacked_proc_runner util/progress_meter
|
||||||
actions/base downloaders/base actions/collection actions/runner config
|
actions/base downloaders/base actions/collection actions/runner config
|
||||||
provisioners/base provisioners/chef systems/base commands/base commands/box})
|
provisioners/base provisioners/chef systems/base commands/base commands/box})
|
|
@ -45,7 +45,7 @@ module Vagrant
|
||||||
|
|
||||||
def wait_for_not_busy(sleeptime=5)
|
def wait_for_not_busy(sleeptime=5)
|
||||||
if @@trap_thread
|
if @@trap_thread
|
||||||
logger.info "Exiting vagrant immediately!"
|
# logger.info "Exiting vagrant immediately!"
|
||||||
Thread.kill(@@trap_thread)
|
Thread.kill(@@trap_thread)
|
||||||
abort
|
abort
|
||||||
return # for tests
|
return # for tests
|
||||||
|
@ -55,12 +55,12 @@ module Vagrant
|
||||||
# Wait while the app is busy
|
# Wait while the app is busy
|
||||||
loop do
|
loop do
|
||||||
break unless busy?
|
break unless busy?
|
||||||
logger.info "Waiting for vagrant to clean itself up..."
|
# logger.info "Waiting for vagrant to clean itself up..."
|
||||||
sleep sleeptime
|
sleep sleeptime
|
||||||
end
|
end
|
||||||
|
|
||||||
# Exit out of the entire script
|
# Exit out of the entire script
|
||||||
logger.info "Exiting vagrant..."
|
# logger.info "Exiting vagrant..."
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,7 +31,7 @@ module Vagrant
|
||||||
if vm.created?
|
if vm.created?
|
||||||
vm.destroy
|
vm.destroy
|
||||||
else
|
else
|
||||||
logger.info "VM '#{name}' not created. Ignoring."
|
vm.env.logger.info "VM '#{name}' not created. Ignoring."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ module Vagrant
|
||||||
if vm.created?
|
if vm.created?
|
||||||
vm.halt(options[:force])
|
vm.halt(options[:force])
|
||||||
else
|
else
|
||||||
logger.info "VM '#{name}' not created. Ignoring."
|
vm.env.logger.info "VM '#{name}' not created. Ignoring."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ module Vagrant
|
||||||
if vm.created?
|
if vm.created?
|
||||||
vm.reload
|
vm.reload
|
||||||
else
|
else
|
||||||
logger.info "VM '#{name}' not created. Ignoring."
|
vm.env.logger.info "VM '#{name}' not created. Ignoring."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ module Vagrant
|
||||||
if vm.created?
|
if vm.created?
|
||||||
vm.resume
|
vm.resume
|
||||||
else
|
else
|
||||||
logger.info "VM '#{name}' not created. Ignoring."
|
vm.env.logger.info "VM '#{name}' not created. Ignoring."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ module Vagrant
|
||||||
if vm.created?
|
if vm.created?
|
||||||
vm.suspend
|
vm.suspend
|
||||||
else
|
else
|
||||||
logger.info "VM '#{name}' not created. Ignoring."
|
vm.env.logger.info "VM '#{name}' not created. Ignoring."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
module Vagrant
|
|
||||||
module Util
|
|
||||||
def logger
|
|
||||||
Logger.singleton_logger
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class Logger < ::Logger
|
|
||||||
@@singleton_logger = nil
|
|
||||||
|
|
||||||
class << self
|
|
||||||
def singleton_logger
|
|
||||||
# TODO: Buffer messages until config is loaded, then output them?
|
|
||||||
if Vagrant.config.loaded?
|
|
||||||
@@singleton_logger ||= Vagrant::Logger.new(Vagrant.config.vagrant.log_output)
|
|
||||||
else
|
|
||||||
Vagrant::Logger.new(nil)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def reset_logger!
|
|
||||||
@@singleton_logger = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def format_message(level, time, progname, msg)
|
|
||||||
"[#{level} #{time.strftime('%m-%d-%Y %X')}] Vagrant: #{msg}\n"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ class CommandsDestroyTest < Test::Unit::TestCase
|
||||||
context "destroying a single VM" do
|
context "destroying a single VM" do
|
||||||
setup do
|
setup do
|
||||||
@foo_vm = mock("vm")
|
@foo_vm = mock("vm")
|
||||||
|
@foo_vm.stubs(:env).returns(@env)
|
||||||
vms = { :foo => @foo_vm }
|
vms = { :foo => @foo_vm }
|
||||||
@env.stubs(:vms).returns(vms)
|
@env.stubs(:vms).returns(vms)
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,6 +36,7 @@ class CommandsHaltTest < Test::Unit::TestCase
|
||||||
context "halting a single VM" do
|
context "halting a single VM" do
|
||||||
setup do
|
setup do
|
||||||
@foo_vm = mock("vm")
|
@foo_vm = mock("vm")
|
||||||
|
@foo_vm.stubs(:env).returns(@env)
|
||||||
vms = { :foo => @foo_vm }
|
vms = { :foo => @foo_vm }
|
||||||
@env.stubs(:vms).returns(vms)
|
@env.stubs(:vms).returns(vms)
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,6 +36,7 @@ class CommandsReloadTest < Test::Unit::TestCase
|
||||||
context "reloading a single VM" do
|
context "reloading a single VM" do
|
||||||
setup do
|
setup do
|
||||||
@foo_vm = mock("vm")
|
@foo_vm = mock("vm")
|
||||||
|
@foo_vm.stubs(:env).returns(@env)
|
||||||
vms = { :foo => @foo_vm }
|
vms = { :foo => @foo_vm }
|
||||||
@env.stubs(:vms).returns(vms)
|
@env.stubs(:vms).returns(vms)
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,6 +36,7 @@ class CommandsResumeTest < Test::Unit::TestCase
|
||||||
context "resuming a single VM" do
|
context "resuming a single VM" do
|
||||||
setup do
|
setup do
|
||||||
@foo_vm = mock("vm")
|
@foo_vm = mock("vm")
|
||||||
|
@foo_vm.stubs(:env).returns(@env)
|
||||||
vms = { :foo => @foo_vm }
|
vms = { :foo => @foo_vm }
|
||||||
@env.stubs(:vms).returns(vms)
|
@env.stubs(:vms).returns(vms)
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,6 +36,7 @@ class CommandsSuspendTest < Test::Unit::TestCase
|
||||||
context "suspending a single VM" do
|
context "suspending a single VM" do
|
||||||
setup do
|
setup do
|
||||||
@foo_vm = mock("vm")
|
@foo_vm = mock("vm")
|
||||||
|
@foo_vm.stubs(:env).returns(@env)
|
||||||
vms = { :foo => @foo_vm }
|
vms = { :foo => @foo_vm }
|
||||||
@env.stubs(:vms).returns(vms)
|
@env.stubs(:vms).returns(vms)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,64 +0,0 @@
|
||||||
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
|
||||||
|
|
||||||
class UtilTest < Test::Unit::TestCase
|
|
||||||
class RegUtil
|
|
||||||
extend Vagrant::Util
|
|
||||||
end
|
|
||||||
|
|
||||||
context "erroring" do
|
|
||||||
# TODO: Any way to stub Kernel.exit? Can't test nicely
|
|
||||||
# otherwise
|
|
||||||
end
|
|
||||||
|
|
||||||
context "logger" do
|
|
||||||
class OtherUtil
|
|
||||||
extend Vagrant::Util
|
|
||||||
end
|
|
||||||
|
|
||||||
setup do
|
|
||||||
@config = Vagrant::Config::Top.new
|
|
||||||
@config.stubs(:loaded?).returns(true)
|
|
||||||
@config.vagrant.log_output = STDOUT
|
|
||||||
Vagrant::Config.stubs(:config).returns(@config)
|
|
||||||
Vagrant::Logger.reset_logger!
|
|
||||||
end
|
|
||||||
|
|
||||||
teardown do
|
|
||||||
Vagrant::Logger.reset_logger!
|
|
||||||
end
|
|
||||||
|
|
||||||
should "return a logger to nil if config is not loaded" do
|
|
||||||
@config.expects(:loaded?).returns(false)
|
|
||||||
logger = RegUtil.logger
|
|
||||||
assert_nil logger.instance_variable_get(:@logdev)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "return a logger using the configured output" do
|
|
||||||
logger = RegUtil.logger
|
|
||||||
logdev = logger.instance_variable_get(:@logdev)
|
|
||||||
assert logger
|
|
||||||
assert !logdev.nil?
|
|
||||||
assert_equal STDOUT, logdev.dev
|
|
||||||
end
|
|
||||||
|
|
||||||
should "only instantiate a logger once" do
|
|
||||||
Vagrant::Logger.expects(:new).once.returns("GOOD")
|
|
||||||
RegUtil.logger
|
|
||||||
RegUtil.logger
|
|
||||||
end
|
|
||||||
|
|
||||||
should "be able to reset the logger" do
|
|
||||||
Vagrant::Logger.expects(:new).twice
|
|
||||||
RegUtil.logger
|
|
||||||
Vagrant::Logger.reset_logger!
|
|
||||||
RegUtil.logger
|
|
||||||
end
|
|
||||||
|
|
||||||
should "return the same logger across classes" do
|
|
||||||
logger = RegUtil.logger
|
|
||||||
other = OtherUtil.logger
|
|
||||||
|
|
||||||
assert logger.equal?(other)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Reference in New Issue