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