Commit 1c062aee authored by Mark Peek's avatar Mark Peek

Add ability to send log output to a file

Using PACKER_LOG=1 causes all the log output to be sent to Stderr. This
change maintains that backward compatility. Anything other than "1" will
be treated as a filename which will have logging appended to that file.
This is useful, for example, to always have debugging available without
cluttering up stdout (and without having to redirect stderr all the time).
parent 0fdf9b09
......@@ -14,12 +14,25 @@ import (
)
func main() {
if os.Getenv("PACKER_LOG") == "" {
switch packer_log := os.Getenv("PACKER_LOG"); packer_log {
case "":
// If we don't have logging explicitly enabled, then disable it
log.SetOutput(ioutil.Discard)
} else {
// Logging is enabled, make sure it goes to stderr
case "1":
// Legacy logging is enabled, make sure it goes to stderr
log.SetOutput(os.Stderr)
default:
{
// Use a file for logging
file, err := os.OpenFile(packer_log, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0600)
if err == nil {
log.SetOutput(file)
} else {
// Problem opening the file, fail back to Stderr
log.SetOutput(os.Stderr)
log.Printf("Could not open %s for logging (%s). Using stderr instead.", packer_log, err.Error())
}
}
}
// If there is no explicit number of Go threads to use, then set it
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment