From baba6af4ffd113bcca02fe74ea301f24d9150a62 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 10 Dec 2011 16:17:09 -0800 Subject: [PATCH] Resource prefixes in UI output work --- lib/vagrant/environment.rb | 2 +- lib/vagrant/ui.rb | 10 +++++----- lib/vagrant/vm.rb | 14 +++++++++++++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index b08c36f62..04fc67354 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -72,7 +72,7 @@ module Vagrant @home_path = opts[:home_path] ui_class = opts[:ui_class] || UI::Silent - @ui = ui_class.new(self) + @ui = ui_class.new("vagrant") @loaded = false @lock_acquired = false diff --git a/lib/vagrant/ui.rb b/lib/vagrant/ui.rb index e7ef405b3..6eb00b3af 100644 --- a/lib/vagrant/ui.rb +++ b/lib/vagrant/ui.rb @@ -10,11 +10,11 @@ module Vagrant # * `error` # * `success` class Interface - attr_accessor :env + attr_accessor :resource - def initialize(env) - @env = env - @logger = Log4r::Logger.new("vagrant::ui::interface") + def initialize(resource) + @logger = Log4r::Logger.new("vagrant::ui::interface") + @resource = resource end [:warn, :error, :info, :success].each do |method| @@ -89,7 +89,7 @@ module Vagrant # This is called by `say` to format the message for output. def format_message(type, message, opts=nil) opts ||= {} - message = "[#{env.resource}] #{message}" if opts[:prefix] + message = "[#{@resource}] #{message}" if opts[:prefix] message end end diff --git a/lib/vagrant/vm.rb b/lib/vagrant/vm.rb index 667fa2a72..2363d710b 100644 --- a/lib/vagrant/vm.rb +++ b/lib/vagrant/vm.rb @@ -159,10 +159,22 @@ module Vagrant def powered_off?; @vm.powered_off? end + def ui + return @_ui if defined?(@_ui) + @_ui = @env.ui.dup + @_ui.resource = @name + @_ui + end + protected def run_action(name, options=nil) - env.action_runner.run(name, { :vm => self }.merge(options || {})) + options = { + :vm => self, + :ui => ui + }.merge(options || {}) + + env.action_runner.run(name, options) end end end