Reconfigure legacy vagrant to utilize hclog
This commit is contained in:
parent
be4bbe902f
commit
819a4d28a4
@ -88,7 +88,7 @@ if ENV["VAGRANT_LOG"] && ENV["VAGRANT_LOG"] != ""
|
||||
|
||||
logger = VagrantLogger.new("vagrant")
|
||||
if ENV["VAGRANT_LOG_FILE"] && ENV["VAGRANT_LOG_FILE"] != ""
|
||||
logger.outputters = Log4r::FileOutputter.new("vagrant", {:filename=>ENV["VAGRANT_LOG_FILE"]} )
|
||||
logger.outputters = Log4r::FileOutputter.new("vagrant", filename: ENV["VAGRANT_LOG_FILE"])
|
||||
else
|
||||
logger.outputters = Log4r::Outputter.stderr
|
||||
end
|
||||
|
||||
@ -236,6 +236,11 @@ module Vagrant
|
||||
def self.enable_server_mode!
|
||||
if !server_mode?
|
||||
SERVER_MODE_CALLBACKS.each(&:call)
|
||||
l = VagrantLogger.new("")
|
||||
lv = VagrantLogger.new("vagrant")
|
||||
l.outputters = Log4r::Outputter.stderr
|
||||
lv.outputters = Log4r::Outputter.stderr
|
||||
Log4r::Outputter.stderr.formatter = Util::HCLogFormatter.new
|
||||
end
|
||||
@_server_mode = true
|
||||
end
|
||||
|
||||
@ -18,6 +18,7 @@ module Vagrant
|
||||
autoload :GuestHosts, 'vagrant/util/guest_hosts'
|
||||
autoload :GuestInspection, 'vagrant/util/guest_inspection'
|
||||
autoload :HashWithIndifferentAccess, 'vagrant/util/hash_with_indifferent_access'
|
||||
autoload :HCLogFormatter, 'vagrant/util/logging_formatter'
|
||||
autoload :InstallShellConfig, 'vagrant/util/install_cli_autocomplete'
|
||||
autoload :InstallZSHShellConfig, 'vagrant/util/install_cli_autocomplete'
|
||||
autoload :InstallBashShellConfig, 'vagrant/util/install_cli_autocomplete'
|
||||
|
||||
@ -24,5 +24,19 @@ module Vagrant
|
||||
CredentialScrubber.desensitize(msg)
|
||||
end
|
||||
end
|
||||
|
||||
class HCLogFormatter < Log4r::BasicFormatter
|
||||
def format(event)
|
||||
d = {
|
||||
"@timestamp" => Time.now.strftime("%Y-%m-%dT%H:%M:%S.%6N%:z"),
|
||||
"@level" => Log4r::LNAMES[event.level].downcase,
|
||||
"@module" => event.fullname.gsub("::", "."),
|
||||
"@message" => format_object(event.data),
|
||||
}
|
||||
d["@caller"] = event.tracer[0] if event.tracer
|
||||
|
||||
d.to_json + "\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user