Merge pull request #9269 from chrisroberts/e-log-timestamp

Provide optional timestamp on log output
This commit is contained in:
Chris Roberts 2017-12-14 12:22:24 -08:00 committed by GitHub
commit 9be2651706
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -52,6 +52,19 @@ if argv.include?("--debug")
ENV["VAGRANT_LOG"] = "debug"
end
# Enable log timestamps if requested
if argv.include?("--timestamp")
argv.delete("--timestamp")
ENV["VAGRANT_LOG_TIMESTAMP"] = "1"
end
# Convenience flag to enable debug with timestamps
if argv.include?("--debug-timestamp")
argv.delete("--debug-timestamp")
ENV["VAGRANT_LOG"] = "debug"
ENV["VAGRANT_LOG_TIMESTAMP"] = "1"
end
# Stdout/stderr should not buffer output
$stdout.sync = true
$stderr.sync = true

View File

@ -41,6 +41,12 @@ if ENV["VAGRANT_LOG"] && ENV["VAGRANT_LOG"] != ""
logger = Log4r::Logger.new("vagrant")
logger.outputters = Log4r::Outputter.stderr
logger.level = level
if ENV["VAGRANT_LOG_TIMESTAMP"]
Log4r::Outputter.stderr.formatter = Log4r::PatternFormatter.new(
pattern: "%d [%5l] %m",
date_pattern: "%F %T"
)
end
logger = nil
end
end