From 967bd65ac6c368c9489a9758a134223982836e2e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 4 Feb 2013 13:46:59 -0800 Subject: [PATCH] Net-SSH logs come out with Vagrant debug logs --- plugins/communicators/ssh/communicator.rb | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/plugins/communicators/ssh/communicator.rb b/plugins/communicators/ssh/communicator.rb index df9309e1e..e815dc3a8 100644 --- a/plugins/communicators/ssh/communicator.rb +++ b/plugins/communicators/ssh/communicator.rb @@ -170,8 +170,25 @@ module VagrantPlugins @logger.info("Attempting SSH. Retries: #{retries}. Timeout: #{timeout}") connection = retryable(:tries => retries, :on => exceptions) do Timeout.timeout(timeout) do - @logger.info("Attempting to connect to SSH: #{ssh_info[:host]}:#{ssh_info[:port]}") - Net::SSH.start(ssh_info[:host], ssh_info[:username], opts) + begin + # This logger will get the Net-SSH log data for us. + ssh_logger_io = StringIO.new + ssh_logger = Logger.new(ssh_logger_io) + + # Setup logging for connections + connect_opts = opts.merge({ + :logger => ssh_logger, + :verbose => :debug + }) + + @logger.info("Attempting to connect to SSH: #{ssh_info[:host]}:#{ssh_info[:port]}") + Net::SSH.start(ssh_info[:host], ssh_info[:username], connect_opts) + ensure + # Make sure we output the connection log + @logger.debug("== Net-SSH connection debug-level log START ==") + @logger.debug(ssh_logger_io.string) + @logger.debug("== Net-SSH connection debug-level log END ==") + end end end rescue Errno::ETIMEDOUT, Timeout::Error