diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index 7003351b7..f4ee2417c 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -100,6 +100,13 @@ module Vagrant File.join(home_path, "boxes") end + # Returns the name of the resource which this environment represents. + # The resource is the VM name if there is a VM it represents, otherwise + # it defaults to "vagrant" + def resource + vm_name || "vagrant" + end + # Returns the VMs associated with this environment. def vms @vms ||= {} @@ -238,7 +245,6 @@ 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! - resource = vm_name || "vagrant" @logger = Util::ResourceLogger.new(resource, self) end diff --git a/lib/vagrant/ui.rb b/lib/vagrant/ui.rb index 03e195af1..61ae9360a 100644 --- a/lib/vagrant/ui.rb +++ b/lib/vagrant/ui.rb @@ -44,8 +44,7 @@ module Vagrant protected def format_message(message) - name = env.vm_name || "vagrant" - "[#{name}] #{message}" + "[#{env.resource}] #{message}" end def line_reset diff --git a/test/vagrant/environment_test.rb b/test/vagrant/environment_test.rb index 65403a4de..2bc381b43 100644 --- a/test/vagrant/environment_test.rb +++ b/test/vagrant/environment_test.rb @@ -128,6 +128,21 @@ class EnvironmentTest < Test::Unit::TestCase end end + context "resource" do + setup do + @env = mock_environment + end + + should "return 'vagrant' as a default" do + assert_equal 'vagrant', @env.resource + end + + should "return the VM name if it is specified" do + @env.stubs(:vm_name).returns("foo") + assert_equal "foo", @env.resource + end + end + context "primary VM helper" do setup do @env = mock_environment