Resource logger now logs to a "logs" directory in the home path
This commit is contained in:
parent
7d89d011fb
commit
e3ff9c7ac3
|
@ -1,6 +1,5 @@
|
||||||
Vagrant::Config.run do |config|
|
Vagrant::Config.run do |config|
|
||||||
# default config goes here
|
# default config goes here
|
||||||
config.vagrant.log_output = STDOUT
|
|
||||||
config.vagrant.dotfile_name = ".vagrant"
|
config.vagrant.dotfile_name = ".vagrant"
|
||||||
config.vagrant.home = "~/.vagrant"
|
config.vagrant.home = "~/.vagrant"
|
||||||
config.vagrant.host = :detect
|
config.vagrant.host = :detect
|
||||||
|
|
|
@ -4,7 +4,6 @@ module Vagrant
|
||||||
configures :vagrant
|
configures :vagrant
|
||||||
|
|
||||||
attr_accessor :dotfile_name
|
attr_accessor :dotfile_name
|
||||||
attr_accessor :log_output
|
|
||||||
attr_accessor :home
|
attr_accessor :home
|
||||||
attr_accessor :host
|
attr_accessor :host
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ module Vagrant
|
||||||
# storing references to the various instances.
|
# storing references to the various instances.
|
||||||
class Environment
|
class Environment
|
||||||
ROOTFILE_NAME = "Vagrantfile"
|
ROOTFILE_NAME = "Vagrantfile"
|
||||||
HOME_SUBDIRS = ["tmp", "boxes"]
|
HOME_SUBDIRS = ["tmp", "boxes", "logs"]
|
||||||
DEFAULT_VM = :default
|
DEFAULT_VM = :default
|
||||||
|
|
||||||
attr_reader :parent # Parent environment (in the case of multi-VMs)
|
attr_reader :parent # Parent environment (in the case of multi-VMs)
|
||||||
|
@ -73,6 +73,11 @@ module Vagrant
|
||||||
home_path.join("boxes")
|
home_path.join("boxes")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Path to the Vagrant logs directory
|
||||||
|
def log_path
|
||||||
|
home_path.join("logs")
|
||||||
|
end
|
||||||
|
|
||||||
# Returns the name of the resource which this environment represents.
|
# Returns the name of the resource which this environment represents.
|
||||||
# The resource is the VM name if there is a VM it represents, otherwise
|
# The resource is the VM name if there is a VM it represents, otherwise
|
||||||
# it defaults to "vagrant"
|
# it defaults to "vagrant"
|
||||||
|
|
|
@ -21,7 +21,6 @@ module Vagrant
|
||||||
str = args.shift || ""
|
str = args.shift || ""
|
||||||
File.open(path.to_s, "w") do |f|
|
File.open(path.to_s, "w") do |f|
|
||||||
f.puts "Vagrant::Config.run do |config|"
|
f.puts "Vagrant::Config.run do |config|"
|
||||||
f.puts "config.vagrant.log_output = nil"
|
|
||||||
f.puts "config.vagrant.home = '#{home_path}'"
|
f.puts "config.vagrant.home = '#{home_path}'"
|
||||||
f.puts str
|
f.puts str
|
||||||
f.puts "end"
|
f.puts "end"
|
||||||
|
|
|
@ -31,7 +31,12 @@ module Vagrant
|
||||||
# instantiated, then the given environment will be used to
|
# instantiated, then the given environment will be used to
|
||||||
# create a new logger.
|
# create a new logger.
|
||||||
def singleton_logger(env=nil)
|
def singleton_logger(env=nil)
|
||||||
@@singleton_logger ||= PlainLogger.new(env.config.vagrant.log_output)
|
return PlainLogger.new(nil) if !env.loaded?
|
||||||
|
|
||||||
|
@@singleton_logger ||= begin
|
||||||
|
file = env.log_path.join("#{Time.now.to_i}.log")
|
||||||
|
PlainLogger.new(file)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Resets the singleton logger (only used for testing).
|
# Resets the singleton logger (only used for testing).
|
||||||
|
|
|
@ -12,29 +12,29 @@ class ResourceLoggerUtilTest < Test::Unit::TestCase
|
||||||
@result = mock("result")
|
@result = mock("result")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return a nil plain logger if the config is not loaded" do
|
should "return a nil plain logger if the environment is not loaded" do
|
||||||
env = vagrant_env
|
env = vagrant_env
|
||||||
env.config.stubs(:loaded?).returns(false)
|
env.stubs(:loaded?).returns(false)
|
||||||
|
|
||||||
Vagrant::Util::PlainLogger.expects(:new).with(nil).returns(@result)
|
Vagrant::Util::PlainLogger.expects(:new).with(nil).returns(@result)
|
||||||
assert_equal @result, @klass.singleton_logger(env)
|
assert_equal @result, @klass.singleton_logger(env)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return a logger with the specified output if environment is ready" do
|
should "return a logger with the output file set if environment is ready" do
|
||||||
output = mock("output")
|
|
||||||
env = vagrant_env
|
env = vagrant_env
|
||||||
env.config.vagrant.log_output = output
|
|
||||||
|
|
||||||
Vagrant::Util::PlainLogger.expects(:new).with(output).returns(@result)
|
Vagrant::Util::PlainLogger.expects(:new).returns(@result).with() do |path|
|
||||||
|
assert path.to_s =~ /logs/
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
assert_equal @result, @klass.singleton_logger(env)
|
assert_equal @result, @klass.singleton_logger(env)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "only load the logger once" do
|
should "only load the logger once" do
|
||||||
output = mock("output")
|
|
||||||
env = vagrant_env
|
env = vagrant_env
|
||||||
env.config.vagrant.log_output = output
|
|
||||||
|
|
||||||
Vagrant::Util::PlainLogger.expects(:new).with(output).returns(@result)
|
Vagrant::Util::PlainLogger.expects(:new).with(anything).returns(@result)
|
||||||
assert_equal @result, @klass.singleton_logger(env)
|
assert_equal @result, @klass.singleton_logger(env)
|
||||||
assert_equal @result, @klass.singleton_logger(env)
|
assert_equal @result, @klass.singleton_logger(env)
|
||||||
assert_equal @result, @klass.singleton_logger(env)
|
assert_equal @result, @klass.singleton_logger(env)
|
||||||
|
|
Loading…
Reference in New Issue