Use custom output to break long log lines. Force encoding.
This commit is contained in:
parent
6a1c5f1c7f
commit
8b7c5efa52
@ -236,14 +236,15 @@ module Vagrant
|
|||||||
def self.enable_server_mode!
|
def self.enable_server_mode!
|
||||||
if !server_mode?
|
if !server_mode?
|
||||||
SERVER_MODE_CALLBACKS.each(&:call)
|
SERVER_MODE_CALLBACKS.each(&:call)
|
||||||
Log4r::Outputter.stderr.formatter = Util::HCLogFormatter.new
|
Util::HCLogOutputter.new("hclog")
|
||||||
|
Log4r::Outputter["hclog"].formatter = Util::HCLogFormatter.new
|
||||||
Log4r::Logger.each_logger do |l|
|
Log4r::Logger.each_logger do |l|
|
||||||
l.outputters = Log4r::Outputter.stderr if l.parent == Log4r::RootLogger.instance
|
l.outputters = Log4r::Outputter["hclog"] if l.parent == Log4r::RootLogger.instance
|
||||||
end
|
end
|
||||||
Log4r::Logger::Repository.class_eval do
|
Log4r::Logger::Repository.class_eval do
|
||||||
def self.[]=(n, l)
|
def self.[]=(n, l)
|
||||||
self.synchronize do
|
self.synchronize do
|
||||||
l.outputters = Log4r::Outputter.stderr if l.parent == Log4r::RootLogger.instance
|
l.outputters = Log4r::Outputter["hclog"] if l.parent == Log4r::RootLogger.instance
|
||||||
instance.loggers[n] = l
|
instance.loggers[n] = l
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -19,6 +19,7 @@ module Vagrant
|
|||||||
autoload :GuestInspection, 'vagrant/util/guest_inspection'
|
autoload :GuestInspection, 'vagrant/util/guest_inspection'
|
||||||
autoload :HashWithIndifferentAccess, 'vagrant/util/hash_with_indifferent_access'
|
autoload :HashWithIndifferentAccess, 'vagrant/util/hash_with_indifferent_access'
|
||||||
autoload :HCLogFormatter, 'vagrant/util/logging_formatter'
|
autoload :HCLogFormatter, 'vagrant/util/logging_formatter'
|
||||||
|
autoload :HCLogOutputter, 'vagrant/util/logging_formatter'
|
||||||
autoload :InstallShellConfig, 'vagrant/util/install_cli_autocomplete'
|
autoload :InstallShellConfig, 'vagrant/util/install_cli_autocomplete'
|
||||||
autoload :InstallZSHShellConfig, 'vagrant/util/install_cli_autocomplete'
|
autoload :InstallZSHShellConfig, 'vagrant/util/install_cli_autocomplete'
|
||||||
autoload :InstallBashShellConfig, 'vagrant/util/install_cli_autocomplete'
|
autoload :InstallBashShellConfig, 'vagrant/util/install_cli_autocomplete'
|
||||||
|
|||||||
@ -27,18 +27,34 @@ module Vagrant
|
|||||||
|
|
||||||
class HCLogFormatter < Log4r::BasicFormatter
|
class HCLogFormatter < Log4r::BasicFormatter
|
||||||
def format(event)
|
def format(event)
|
||||||
d = {
|
message = format_object(event.data).
|
||||||
"@timestamp" => Time.now.strftime("%Y-%m-%dT%H:%M:%S.%6N%:z"),
|
force_encoding('UTF-8').
|
||||||
"@level" => Log4r::LNAMES[event.level].downcase,
|
scrub("?")
|
||||||
"@module" => event.fullname.gsub("::", "."),
|
if message.count("\n") > 40
|
||||||
"@message" => format_object(event.data),
|
message = message.split("\n").each_slice(40).to_a
|
||||||
}
|
message = [message.shift.join("\n")] + message.map { |m|
|
||||||
d["@caller"] = event.tracer[0] if event.tracer
|
"continued...\n" + m.join("\n") }
|
||||||
|
else
|
||||||
|
message = [message]
|
||||||
|
end
|
||||||
|
|
||||||
# TODO(spox): fix this with force encoding on the message
|
message.map do |msg|
|
||||||
begin
|
d = {
|
||||||
|
"@timestamp" => Time.now.strftime("%Y-%m-%dT%H:%M:%S.%6N%:z"),
|
||||||
|
"@level" => Log4r::LNAMES[event.level].downcase,
|
||||||
|
"@module" => event.fullname.gsub("::", "."),
|
||||||
|
"@message" => msg,
|
||||||
|
}
|
||||||
|
d["@caller"] = event.tracer[0] if event.tracer
|
||||||
d.to_json + "\n"
|
d.to_json + "\n"
|
||||||
rescue
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class HCLogOutputter < Log4r::StderrOutputter
|
||||||
|
def write(data)
|
||||||
|
data.each do |d|
|
||||||
|
super(d)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user