Remove logger from the VM and put it on the environment
This commit is contained in:
parent
4a20bfe7fc
commit
6e757e7ab7
|
@ -34,7 +34,7 @@ module Vagrant
|
|||
# removes the need to prefix `logger` with `@runner` over and
|
||||
# over.
|
||||
def logger
|
||||
runner.logger
|
||||
runner.env.logger
|
||||
end
|
||||
|
||||
# Initialization of the action, passing any arguments which may have
|
||||
|
|
|
@ -197,7 +197,8 @@ module Vagrant
|
|||
# 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)
|
||||
resource = vm_name || "vagrant"
|
||||
@logger = ResourceLogger.new(resource, self)
|
||||
end
|
||||
|
||||
# Loads the home directory path and creates the necessary subdirectories
|
||||
|
|
|
@ -92,7 +92,7 @@ module Vagrant
|
|||
stat = File.stat(key_path)
|
||||
|
||||
if stat.owned? && file_perms(key_path) != "600"
|
||||
logger.info "Permissions on private key incorrect, fixing..."
|
||||
env.logger.info "Permissions on private key incorrect, fixing..."
|
||||
File.chmod(0600, key_path)
|
||||
|
||||
error_and_exit(:ssh_bad_permissions, :key_path => key_path) if file_perms(key_path) != "600"
|
||||
|
|
|
@ -4,7 +4,6 @@ module Vagrant
|
|||
|
||||
attr_reader :env
|
||||
attr_reader :system
|
||||
attr_reader :logger
|
||||
attr_reader :name
|
||||
attr_accessor :vm
|
||||
|
||||
|
@ -43,8 +42,6 @@ module Vagrant
|
|||
# Load the associated system.
|
||||
load_system!
|
||||
end
|
||||
|
||||
@logger = ResourceLogger.new(@name, @env)
|
||||
end
|
||||
|
||||
# Loads the system associated with the VM. The system class is
|
||||
|
|
|
@ -105,7 +105,7 @@ class Test::Unit::TestCase
|
|||
mock_vm.stubs(:invoke_around_callback).yields
|
||||
mock_vm.stubs(:actions).returns([action])
|
||||
mock_vm.stubs(:env).returns(mock_environment)
|
||||
mock_vm.stubs(:logger).returns(Vagrant::ResourceLogger.new("mock", nil))
|
||||
mock_vm.env.stubs(:logger).returns(Vagrant::ResourceLogger.new("mock", nil))
|
||||
|
||||
mock_ssh = Vagrant::SSH.new(mock_vm.env)
|
||||
mock_ssh.stubs(:execute)
|
||||
|
|
|
@ -351,6 +351,26 @@ class EnvironmentTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
context "loading logger" do
|
||||
setup do
|
||||
@env = mock_environment
|
||||
@env.stubs(:vm_name).returns(nil)
|
||||
end
|
||||
|
||||
should "use 'vagrant' by default" do
|
||||
assert @env.vm_name.nil? # sanity
|
||||
@env.load_logger!
|
||||
assert_equal "vagrant", @env.logger.resource
|
||||
end
|
||||
|
||||
should "use the vm name if available" do
|
||||
name = "foo"
|
||||
@env.stubs(:vm_name).returns(name)
|
||||
@env.load_logger!
|
||||
assert_equal name, @env.logger.resource
|
||||
end
|
||||
end
|
||||
|
||||
context "loading home directory" do
|
||||
setup do
|
||||
@env = mock_environment
|
||||
|
|
|
@ -54,16 +54,6 @@ class VMTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
context "the logger" do
|
||||
should "create a logger for the proper environment" do
|
||||
logger = @vm.logger
|
||||
assert logger
|
||||
assert logger.is_a?(Vagrant::ResourceLogger)
|
||||
assert_equal @vm.env, logger.env
|
||||
assert_equal @vm_name, logger.resource
|
||||
end
|
||||
end
|
||||
|
||||
context "accessing the SSH object" do
|
||||
setup do
|
||||
# Reset this to nil to force the reload
|
||||
|
|
Loading…
Reference in New Issue