diff --git a/lib/vagrant/actions/base.rb b/lib/vagrant/actions/base.rb index 922a89008..5d35f43d3 100644 --- a/lib/vagrant/actions/base.rb +++ b/lib/vagrant/actions/base.rb @@ -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 diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index adb6f6e52..57d2f5639 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -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 diff --git a/lib/vagrant/ssh.rb b/lib/vagrant/ssh.rb index 2f5f8ec55..0e92d7e7b 100644 --- a/lib/vagrant/ssh.rb +++ b/lib/vagrant/ssh.rb @@ -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" diff --git a/lib/vagrant/vm.rb b/lib/vagrant/vm.rb index cb6dc49ff..e77cb17dc 100644 --- a/lib/vagrant/vm.rb +++ b/lib/vagrant/vm.rb @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb index 42b746251..41b06e3b0 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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) diff --git a/test/vagrant/environment_test.rb b/test/vagrant/environment_test.rb index 60cf2a0e8..2b633fa4e 100644 --- a/test/vagrant/environment_test.rb +++ b/test/vagrant/environment_test.rb @@ -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 diff --git a/test/vagrant/vm_test.rb b/test/vagrant/vm_test.rb index 3aee41e00..9158dcb9b 100644 --- a/test/vagrant/vm_test.rb +++ b/test/vagrant/vm_test.rb @@ -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