Reconfigure legacy vagrant to utilize hclog

This commit is contained in:
Chris Roberts 2021-10-13 17:19:24 -07:00 committed by Paul Hinze
parent be4bbe902f
commit 819a4d28a4
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
4 changed files with 21 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -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