Provide optional timestamp on log output
Enable log message output to be prefixed with the date and time. Include CLI flag to optionally enable `--timestamp` and a convenience flag to enable debug logging with timestamps at the same time `--debug-timestamp`.
This commit is contained in:
parent
3a5729015a
commit
da42bfa8ac
13
bin/vagrant
13
bin/vagrant
|
@ -52,6 +52,19 @@ if argv.include?("--debug")
|
||||||
ENV["VAGRANT_LOG"] = "debug"
|
ENV["VAGRANT_LOG"] = "debug"
|
||||||
end
|
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/stderr should not buffer output
|
||||||
$stdout.sync = true
|
$stdout.sync = true
|
||||||
$stderr.sync = true
|
$stderr.sync = true
|
||||||
|
|
|
@ -41,6 +41,12 @@ if ENV["VAGRANT_LOG"] && ENV["VAGRANT_LOG"] != ""
|
||||||
logger = Log4r::Logger.new("vagrant")
|
logger = Log4r::Logger.new("vagrant")
|
||||||
logger.outputters = Log4r::Outputter.stderr
|
logger.outputters = Log4r::Outputter.stderr
|
||||||
logger.level = level
|
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
|
logger = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue