Basic logging
This commit is contained in:
parent
0db2ec9d43
commit
11dc005d75
|
@ -1,5 +1,6 @@
|
||||||
require 'pathname'
|
require 'pathname'
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
|
require 'logger'
|
||||||
|
|
||||||
module Vagrant
|
module Vagrant
|
||||||
# Represents a single Vagrant environment. A "Vagrant environment" is
|
# Represents a single Vagrant environment. A "Vagrant environment" is
|
||||||
|
@ -79,6 +80,11 @@ module Vagrant
|
||||||
|
|
||||||
@loaded = false
|
@loaded = false
|
||||||
@lock_acquired = false
|
@lock_acquired = false
|
||||||
|
|
||||||
|
logger.info "Environment initialized (#{self})"
|
||||||
|
logger.info " - cwd: #{cwd}"
|
||||||
|
logger.info " - parent: #{parent}"
|
||||||
|
logger.info " - vm: #{vm}"
|
||||||
end
|
end
|
||||||
|
|
||||||
#---------------------------------------------------------------
|
#---------------------------------------------------------------
|
||||||
|
@ -283,11 +289,22 @@ module Vagrant
|
||||||
# @return [Logger]
|
# @return [Logger]
|
||||||
def logger
|
def logger
|
||||||
return parent.logger if parent
|
return parent.logger if parent
|
||||||
return @logger if defined?(@logger)
|
return @logger if @logger
|
||||||
|
|
||||||
@logger = Logger.new(log_path.join("#{Time.now.to_i}.log"))
|
# Figure out where the output should go to.
|
||||||
|
output = nil
|
||||||
|
if ENV["VAGRANT_LOG"] == "STDOUT"
|
||||||
|
output = STDOUT
|
||||||
|
elsif ENV["VAGRANT_LOG"]
|
||||||
|
output = ENV["VAGRANT_LOG"]
|
||||||
|
else
|
||||||
|
output = log_path.join("#{Time.now.to_i}.log")
|
||||||
|
end
|
||||||
|
|
||||||
|
# Create the logger and custom formatter
|
||||||
|
@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}"
|
"#{datetime} - [#{resource}] #{msg}\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
@logger
|
@logger
|
||||||
|
@ -378,7 +395,15 @@ module Vagrant
|
||||||
def load!
|
def load!
|
||||||
if !loaded?
|
if !loaded?
|
||||||
@loaded = true
|
@loaded = true
|
||||||
|
|
||||||
|
if !parent
|
||||||
|
# We only need to check the virtualbox version once, so do it on
|
||||||
|
# the parent most environment and then forget about it
|
||||||
|
logger.info "Environment not loaded. Checking virtual box version..."
|
||||||
self.class.check_virtualbox!
|
self.class.check_virtualbox!
|
||||||
|
end
|
||||||
|
|
||||||
|
logger.info "Loading configuration..."
|
||||||
load_config!
|
load_config!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -422,9 +447,6 @@ module Vagrant
|
||||||
# value in the config ivar.
|
# value in the config ivar.
|
||||||
@config = @config_loader.load(self)
|
@config = @config_loader.load(self)
|
||||||
|
|
||||||
# (re)load the logger
|
|
||||||
@logger = nil
|
|
||||||
|
|
||||||
if first_run
|
if first_run
|
||||||
# After the first run we want to load the configuration again since
|
# After the first run we want to load the configuration again since
|
||||||
# it can change due to box Vagrantfiles and home directory Vagrantfiles
|
# it can change due to box Vagrantfiles and home directory Vagrantfiles
|
||||||
|
|
Loading…
Reference in New Issue