Environment uses new logger
This commit is contained in:
parent
75b1df2f2f
commit
470c8de099
|
@ -20,6 +20,7 @@ module Vagrant
|
||||||
attr_reader :vms
|
attr_reader :vms
|
||||||
attr_reader :active_list
|
attr_reader :active_list
|
||||||
attr_reader :commands
|
attr_reader :commands
|
||||||
|
attr_reader :logger
|
||||||
|
|
||||||
#---------------------------------------------------------------
|
#---------------------------------------------------------------
|
||||||
# Class Methods
|
# Class Methods
|
||||||
|
@ -119,6 +120,7 @@ module Vagrant
|
||||||
# such as `vm`, `config`, etc. on this environment. The order this
|
# such as `vm`, `config`, etc. on this environment. The order this
|
||||||
# method calls its other methods is very particular.
|
# method calls its other methods is very particular.
|
||||||
def load!
|
def load!
|
||||||
|
load_logger!
|
||||||
load_root_path!
|
load_root_path!
|
||||||
load_config!
|
load_config!
|
||||||
load_home_directory!
|
load_home_directory!
|
||||||
|
@ -171,7 +173,6 @@ module Vagrant
|
||||||
# Load each of the config files in order
|
# Load each of the config files in order
|
||||||
config_queue.each do |item|
|
config_queue.each do |item|
|
||||||
if item.is_a?(String) && File.exist?(item)
|
if item.is_a?(String) && File.exist?(item)
|
||||||
logger.info "Loading config from #{item}..."
|
|
||||||
load item
|
load item
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
@ -184,6 +185,19 @@ module Vagrant
|
||||||
|
|
||||||
# Execute the configuration stack and store the result
|
# Execute the configuration stack and store the result
|
||||||
@config = Config.execute!
|
@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
|
end
|
||||||
|
|
||||||
# Loads the home directory path and creates the necessary subdirectories
|
# Loads the home directory path and creates the necessary subdirectories
|
||||||
|
|
|
@ -24,7 +24,7 @@ module Vagrant
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def singleton_logger(env=nil)
|
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)
|
@@singleton_logger ||= Util::PlainLogger.new(env.config.vagrant.log_output)
|
||||||
else
|
else
|
||||||
Util::PlainLogger.new(nil)
|
Util::PlainLogger.new(nil)
|
||||||
|
|
|
@ -24,6 +24,7 @@ class Test::Unit::TestCase
|
||||||
|
|
||||||
Vagrant::Config.run do |config|
|
Vagrant::Config.run do |config|
|
||||||
config.vagrant.dotfile_name = ".vagrant"
|
config.vagrant.dotfile_name = ".vagrant"
|
||||||
|
config.vagrant.log_output = nil
|
||||||
|
|
||||||
config.ssh.username = "foo"
|
config.ssh.username = "foo"
|
||||||
config.ssh.password = "bar"
|
config.ssh.password = "bar"
|
||||||
|
@ -73,6 +74,12 @@ class Test::Unit::TestCase
|
||||||
config = Vagrant::Config.execute!
|
config = Vagrant::Config.execute!
|
||||||
|
|
||||||
environment.instance_variable_set(:@config, config)
|
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
|
environment
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -167,6 +167,7 @@ class EnvironmentTest < Test::Unit::TestCase
|
||||||
context "overall load method" do
|
context "overall load method" do
|
||||||
should "load! should call proper sequence and return itself" do
|
should "load! should call proper sequence and return itself" do
|
||||||
call_seq = sequence("call_sequence")
|
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_root_path!).once.in_sequence(call_seq)
|
||||||
@env.expects(:load_config!).once.in_sequence(call_seq)
|
@env.expects(:load_config!).once.in_sequence(call_seq)
|
||||||
@env.expects(:load_home_directory!).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"
|
@home_path = "/bar"
|
||||||
@env.stubs(:root_path).returns(@root_path)
|
@env.stubs(:root_path).returns(@root_path)
|
||||||
@env.stubs(:home_path).returns(@home_path)
|
@env.stubs(:home_path).returns(@home_path)
|
||||||
|
@env.stubs(:load_logger!)
|
||||||
|
|
||||||
@parent_env = mock_environment
|
@parent_env = mock_environment
|
||||||
|
|
||||||
|
@ -340,6 +342,13 @@ class EnvironmentTest < Test::Unit::TestCase
|
||||||
@env.load_config!
|
@env.load_config!
|
||||||
assert_equal result, @env.config
|
assert_equal result, @env.config
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "loading home directory" do
|
context "loading home directory" do
|
||||||
|
|
Loading…
Reference in New Issue