Environment uses new logger

This commit is contained in:
Mitchell Hashimoto 2010-05-20 16:36:17 -07:00
parent 75b1df2f2f
commit 470c8de099
4 changed files with 32 additions and 2 deletions

View File

@ -20,6 +20,7 @@ module Vagrant
attr_reader :vms
attr_reader :active_list
attr_reader :commands
attr_reader :logger
#---------------------------------------------------------------
# Class Methods
@ -119,6 +120,7 @@ module Vagrant
# such as `vm`, `config`, etc. on this environment. The order this
# method calls its other methods is very particular.
def load!
load_logger!
load_root_path!
load_config!
load_home_directory!
@ -171,7 +173,6 @@ module Vagrant
# Load each of the config files in order
config_queue.each do |item|
if item.is_a?(String) && File.exist?(item)
logger.info "Loading config from #{item}..."
load item
next
end
@ -184,6 +185,19 @@ module Vagrant
# Execute the configuration stack and store the result
@config = Config.execute!
# (re)load the logger
load_logger!
end
# Loads the logger for this environment. This is called by
# {#load_config!} so that the logger is only loaded after
# configuration information is available. The logger is also
# loaded early on in the load chain process so that the various
# references to logger won't throw nil exceptions, but by default
# the logger will just send the log data to a black hole.
def load_logger!
@logger = ResourceLogger.new("vagrant", self)
end
# Loads the home directory path and creates the necessary subdirectories

View File

@ -24,7 +24,7 @@ module Vagrant
class << self
def singleton_logger(env=nil)
if env && env.config.loaded?
if env && env.config && env.config.loaded?
@@singleton_logger ||= Util::PlainLogger.new(env.config.vagrant.log_output)
else
Util::PlainLogger.new(nil)

View File

@ -24,6 +24,7 @@ class Test::Unit::TestCase
Vagrant::Config.run do |config|
config.vagrant.dotfile_name = ".vagrant"
config.vagrant.log_output = nil
config.ssh.username = "foo"
config.ssh.password = "bar"
@ -73,6 +74,12 @@ class Test::Unit::TestCase
config = Vagrant::Config.execute!
environment.instance_variable_set(:@config, config)
# Setup the logger. We create it then reset it so that subsequent
# calls will recreate it for us.
environment.load_logger!
environment.logger.class.reset_singleton_logger!
environment
end

View File

@ -167,6 +167,7 @@ class EnvironmentTest < Test::Unit::TestCase
context "overall load method" do
should "load! should call proper sequence and return itself" do
call_seq = sequence("call_sequence")
@env.expects(:load_logger!).once.in_sequence(call_seq)
@env.expects(:load_root_path!).once.in_sequence(call_seq)
@env.expects(:load_config!).once.in_sequence(call_seq)
@env.expects(:load_home_directory!).once.in_sequence(call_seq)
@ -249,6 +250,7 @@ class EnvironmentTest < Test::Unit::TestCase
@home_path = "/bar"
@env.stubs(:root_path).returns(@root_path)
@env.stubs(:home_path).returns(@home_path)
@env.stubs(:load_logger!)
@parent_env = mock_environment
@ -340,6 +342,13 @@ class EnvironmentTest < Test::Unit::TestCase
@env.load_config!
assert_equal result, @env.config
end
should "reload the logger after executing" do
load_seq = sequence("load_seq")
Vagrant::Config.expects(:execute!).once.returns(nil).in_sequence(load_seq)
@env.expects(:load_logger!).once.in_sequence(load_seq)
@env.load_config!
end
end
context "loading home directory" do