Logging of `vagrant`, action running, and warden

This commit is contained in:
Mitchell Hashimoto 2011-07-10 16:48:00 -07:00
parent be3f7ffbfc
commit 907c3b318a
4 changed files with 14 additions and 3 deletions

View File

@ -5,6 +5,10 @@ require 'vagrant/cli'
env = Vagrant::Environment.new env = Vagrant::Environment.new
begin begin
# Begin logging early here
env.logger.info "`vagrant` invoked: #{ARGV.inspect}"
# Disable color if the proper argument was passed
shell = ARGV.include?("--no-color") ? Thor::Shell::Basic.new : Thor::Base.shell.new shell = ARGV.include?("--no-color") ? Thor::Shell::Basic.new : Thor::Base.shell.new
# Set the UI early in case any errors are raised, and load # Set the UI early in case any errors are raised, and load

View File

@ -129,6 +129,7 @@ module Vagrant
end end
# We place a process lock around every action that is called # We place a process lock around every action that is called
env.logger.info "Running action: #{callable_id}"
env.lock do env.lock do
Busy.busy(int_callback) { callable.call(action_environment) } Busy.busy(int_callback) { callable.call(action_environment) }
end end

View File

@ -25,13 +25,16 @@ module Vagrant
# Call the next middleware in the sequence, appending to the stack # Call the next middleware in the sequence, appending to the stack
# of "recoverable" middlewares in case something goes wrong! # of "recoverable" middlewares in case something goes wrong!
raise Errors::VagrantInterrupt if env.interrupted? raise Errors::VagrantInterrupt if env.interrupted?
@stack.unshift(@actions.shift).first.call(env) action = @actions.shift
env["logger"].info("warden") { "Calling action: #{action}" }
@stack.unshift(action).first.call(env)
raise Errors::VagrantInterrupt if env.interrupted? raise Errors::VagrantInterrupt if env.interrupted?
rescue SystemExit rescue SystemExit
# This means that an "exit" or "abort" was called. In these cases, # This means that an "exit" or "abort" was called. In these cases,
# we just exit immediately. # we just exit immediately.
raise raise
rescue Exception => e rescue Exception => e
env["logger"].info("warden") { "Error occurred: #{e}" }
env["vagrant.error"] = e env["vagrant.error"] = e
# Something went horribly wrong. Start the rescue chain then # Something went horribly wrong. Start the rescue chain then
@ -46,7 +49,10 @@ module Vagrant
# which has already run, in reverse order. # which has already run, in reverse order.
def begin_rescue(env) def begin_rescue(env)
@stack.each do |act| @stack.each do |act|
act.recover(env) if act.respond_to?(:recover) if act.respond_to?(:recover)
env["logger"].info("warden") { "Calling recover: #{act}" }
act.recover(env)
end
end end
# Clear stack so that warden down the middleware chain doesn't # Clear stack so that warden down the middleware chain doesn't

View File

@ -309,7 +309,7 @@ module Vagrant
# Create the logger and custom formatter # Create the logger and custom formatter
@logger = Logger.new(output) @logger = Logger.new(output)
@logger.formatter = Proc.new do |severity, datetime, progname, msg| @logger.formatter = Proc.new do |severity, datetime, progname, msg|
"#{datetime} - [#{resource}] #{msg}\n" "#{datetime} - #{progname} - [#{resource}] #{msg}\n"
end end
@logger @logger